ENGR2100U
Computational Engineering Applications
LAB 5: Curve fitting
January 2021
Laboratory
5
Curve fitting
This experiment will introduce the embedded fitting techniques (polyfit) and functions
fitting techniques (Newton’s Polynomial and Lagrange Polynomial).
PLEASE, SOLVE THIS LAB ONLY DURING THE LABORATORY TIME, AT HOME
YOU SHOULD ONLY DO THE PRELAB TASKS.
Objectives
Gain familiarity with MATLAB scripting and function files, .m, .mat., .csv, .txt.
Gain familiarity with MATLAB .m file script writing.
Gain familiarity with tic toc
Gain familiarity with for loop
Gain familiarity with plot
Gain familiarity with MATLAB function writing.
Gain familiarity with fitting functions and their pros and cons.
Understand how to apply into real data collected from experiments.
Components/Software
MATLAB R2019b
Other Useful Information
MATLAB Documentation
MATLAB Examples
MATLAB Question/Answer
Prelab Section
1. Introduction:
Ensure you have installed MATLAB R2019b on your computer.
Get familiar with polyfit
Get familiar with polyval
Get familiar with Newton`s Polynomial
Get familiar with Lagrange Polynomial
Lab Section
Lab Tasks
1) Consider the following input data:
x = [0 3.6 10 12 16.4 18.4 24];
y = [52 32.830 6.670 7 5.030 2*pi 8];
Use polyfit to
a) determine the best polynomial fit for desired order n (1, 2, 3, 4, 5)
b) determine the error between fitted and experimental data for the values of x
c) determine the time to compute order range 0 to 6 using tic toc command
d) Bonus: compare the computational time versus polyfit order n (1, 2, 3, 4, 5).
2) Consider the following input data:
Table 1 DATA
SOC = 100*[0
0.05 0.10 0.15 0.20 0.25 0.30 0.35 0.40
0.45 0.50 0.55 0.60 0.65 0.70 0.75 0.80 0.85 0.90 0.95 1];
V = [2.5 3.293
3.415
3.451 3.496 3.547 3.589
3.614 3.635 3.657 3.683 3.717 3.757 3.806 3.862
3.896 3.925 3.957 3.997 4.04
4.074 ];
Consider y-axis Voltage [V] and x-axis SOC [%]. Use polyfit to:
a) determine the best polynomial fit for desired order n (2, 4, 6, 8).
b) determine the error between fitted and experimental data for the values of x
c) determine the time to compute polyfit with different order (2, 4, 6, 8) using tic toc
d) Bonus: compare the computational time versus polyfit order n (2, 4, 6, 8).
e) Calculate the Voltage at 100%, 75%, 50% and 0% using fitted function with n = 2, 4, 6, 8.
3) Consider Ohm’s law:
𝑅1 = 1𝛺
𝑉(𝑆𝑂𝐶) = 𝑅1 ⅈ(𝑆𝑂𝐶)
ⅈ(𝑆𝑂𝐶) =
𝑣(𝑆𝑂𝐶)
𝑅1
𝑃(𝑆𝑂𝐶) = 𝑣(𝑆𝑂𝐶) ⋅ ⅈ(𝑆𝑂𝐶)
(1)
(2)
(3)
Consider the data presented in Table 1 and:
i) Use equation 2 to find the current function ⅈ(𝑆𝑂𝐶), using the fitted 𝑉(𝑆𝑂𝐶) from (a). Plot
ⅈ(𝑆𝑂𝐶) vs 𝑆𝑂𝐶.
ii)
Use equation 3 to find the power function 𝑃(𝑆𝑂𝐶) using fitted 𝑉(𝑆𝑂𝐶) from (a) and
ⅈ(𝑆𝑂𝐶) from (i). Plot 𝑃(𝑆𝑂𝐶) vs 𝑆𝑂𝐶.
iii)
Consider a constant-power (CP) during the entire range of SOC is needed to be 5W.
Find the new current function ⅈ𝐶𝑃 (𝑆𝑂𝐶) in order to have the CP over the entire range
of SOC.
What is the error between fitted curve and experimental results for 100%, 75%, 50%
and 0%?
iv)
v)
What would be the error if polyfit is used with order 2?