Curve Fitting
Curve Fitting
REGRESSION ANALYSIS
OR
CURVE FITTING
Bushra Fatima
NED University of Engineering & Technology August 19, 2020
Regression Analysis or Curve Fitting
•Curve fitting, also called regression analysis, is a
process of fitting a function to a set of data points.
•The function can be used as a mathematical
model of the data.
•Since there are many types of functions (linear,
polynomial, power, exponential, etc.), curve fitting
can be a complicated process.
Curve Fitting with polynomials
Polynomials can be used to fit data points in two ways.
• When n points (xi, yi) are given polynomial of degree (n-1) that passes
through all the points.
!!! polyfit function does NOT plot the graph. It only gives the coefficients
A set of seven points is given by (0.9, 0.9), (1.5, 1.5), (3, 2.5), (4, 5.1),(6, 4.5), (8, 4.9),
and (9.5, 6.3).
ln 𝑦 = 𝑚 ln 𝑥 + ln 𝑏
l𝑜𝑔 𝑦 = 𝑚𝑥 + l𝑜𝑔 𝑏
Curve Fitting with functions other than polynomials
Curve Fitting with functions other than polynomials
Solution: Scatter Plot (linear axes)
1. Linear function
2. Logarithmic function
3. power function
4. Exponential function
5. Reciprocal function
Solution: Scatter Plot (semi log axis)
Checking for Exponential function
Solution: Scatter Plot (linear axes)
Checking for reciprocal function
Solution: selected plot:
Function chosen: Exponential function
t=0:0.5:5;
w=[6 4.83 3.7 3.15 2.41 1.83 1.49 1.21 0.96 0.73 0.64];
p=polyfit(t,log(w),1);
m=p(1)
b=exp(p(2))
tp=0:0.1:5;
wp=b*exp(m*tp);
plot(t,w,'o',tp,wp)
xlabel('t'), ylabel('w')
Solution: selected plot:
Function chosen: Exponential function