0% found this document useful (0 votes)
28 views

MATLAB Examples - Curve Fitting

CURVE FITTING

Uploaded by

santha kumari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views

MATLAB Examples - Curve Fitting

CURVE FITTING

Uploaded by

santha kumari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Curve Fitting

• In the previous section we found interpolated points, i.e., we found values


between the measured points using the interpolation technique.
• It would be more convenient to model the data as a mathematical function
𝑦 = 𝑓(𝑥).
• Then we can easily calculate any data we want based on this model.

Mathematical Model
Data
Curve Fitting
• MATLAB has built-in curve fitting functions that allows us to
create empiric data model.
• It is important to have in mind that these models are good only
in the region we have collected data.
• Here are some of the functions available in MATLAB used for
curve fitting:
- polyfit()
- polyval()
• These techniques use a polynomial of degree N that fits the data
Y best in a least-squares sense.
Regression Models
Linear Regression:
𝑦(𝑥) = 𝑎𝑥 + 𝑏
Polynomial Regression:
𝑦 𝑥 = 𝑎! 𝑥 " + 𝑎# 𝑥 "$# + ⋯ + 𝑎"$# 𝑥 + 𝑎"
1.order (linear):
𝑦(𝑥) = 𝑎𝑥 + 𝑏
2.order:
𝑦 𝑥 = 𝑎𝑥 % + 𝑏𝑥 + 𝑐
etc.
Linear Regression
Given the following data: Temperature, T [ oC] Energy, u [KJ/kg]
100 2506.7
150 2582.8
200 2658.1
250 2733.7
300 2810.4
400 2967.9
500 3131.6

Plot u versus T.
Find the linear regression model from the data
𝑦 = 𝑎𝑥 + 𝑏
Plot it in the same graph.
T = [100, 150, 200, 250, 300, 400, 500];
u=[2506.7, 2582.8, 2658.1, 2733.7, 2810.4, 2967.9, 3131.6];

n=1; % 1.order polynomial(linear regression)


p=polyfit(u,T,n);

a=p(1)
b=p(2)

x=u;
ymodel=a*x+b;

plot(u,T,'o',u,ymodel)

a=
0.6415 𝑦 ≈ 0.64𝑥 − 1.5 / 10,
b=
-1.5057e+003
i.e, we get a polynomial 𝑝 = [0.6, −1.5 + 10! ]

You might also like