Curve Fitting Assignment Sabbir 17146555
Curve Fitting Assignment Sabbir 17146555
Curve Fitting Assignment Sabbir 17146555
Curve fitting is the process of constructing a curve, or mathematical function, that has
the best fit to a series of data points, possibly subject to constraints. It can be use in various
engineering application such as estimating wireless pathloss model, machine learning, and
modelling a certain system from sensors. Practical engineering problems can be solve using
the correct mathematical modelling.
Question-1
𝐹 = 𝛼𝑉𝛽
By linearizing the equation, we get,
log(F) = y,
log (α) = a0,
β = a1,
log(V) = x
a) Linearized the data and calculate the coefficients (values of 𝑎1 and 𝑎0) that minimizes
the error between the model and the data. Using equation a1 a0 as below
y = 1.9135 – 2.9073*x
𝑊 = 81.9449 ∗ 𝑉 −2.9073
%Calculate St Sr
% St is quantify spread of data about the mean prior to
regression
% Sr is quantify spread of data about the regression line
%(or curve)
St_P=0;
Sr_P=0;
for i= 1:n
St_P = St_P + (y(i)-ybar)^2;
Sr_P = Sr_P + (y(i)-a0_P-a1_P.*x(i))^2;
end
%Define linear fit r^2
r_P= sqrt((St_P-Sr_P)/St_P)
r2_P=r_P^2
A specific way that a quantity may increase over time. It occurs when the instantaneous
rate of change of a quantity with respect to time is proportional to the quantity itself.
A= α𝒆𝜷𝒕
By linearizing this equation, we get
y = a0 + a1*x……(iv)
ln(A) = y,
ln (α) = a0,
β = a1,
t=x
a) Linearized the data and calculate the coefficients (values of 𝑎1 and 𝑎0) that
minimizes the error between the model and the data.
y = 3.9659 -0.7437*x
W = 52.7666*𝑒 −0.7437∗𝑉
c) The linear fir r^2 value –
%Calculate St Sr
St_E=0;
Sr_E=0;
for i= 1:n
St_E = St_E + (y(i)-ybar)^2;
Sr_E = Sr_E + (y(i)-a0_E-a1_E.*x(i))^2;
end
%Define linear fit r^2
r2_E= (St_E-Sr_E)/St_E
The output –
Saturation-Growth Rate model come from situations where the derivative of the
dependent variable is proportional to the square of the ratio of the dependent variable to the
independent variable.
C = αt / (β+t)
y = a0 + a1*x……….(vi)
1/C =y
1/α = a0
β / α = a1
1/ t = x
a) Linearized the data and calculate the coefficients (values of 𝑎1 and 𝑎0) that minimizes
the error between the model and the data.
y = 3.8083 -5.8595*x
The output:
W = (0.2626*V)/(-1.5386*V)
The output:
From above shown models, the coefficient for the Power Law model is 0.9830, which is closer
to perfect fit 1. which means the curves are better fit Power Law model comparing to Saturation
growth rate, r^2 = 0.3599 and Exponential models, r^2 = 0.9057. From the obtained result, it
is justified to say that Power Law model is suitable to represent the data.
Reference Code:
y =log10(W);
x = log10(V);
%Calculate a1 power law
xi=sum(x); %summation of x data
yi=sum(y); %summation of y data
xiyi= sum(x.*y); %summation of x*y data
xi2= sum(x.^2); %summation of x squared data
a1_P = (n*xiyi-xi*yi)/(n*xi2 - xi^2)
%Calculate a0 power law
ybar = yi/n; % mean value of y
xbar = xi/n; %mean value of x
a0_P = ybar - a1_P*xbar
%Calculate St Sr
% St is quantify spread of data about the mean prior to regression
% Sr is quantify spread of data about the regression line
%(or curve)
St_P=0;
Sr_P=0;
for i= 1:n
St_P = St_P + (y(i)-ybar)^2;
Sr_P = Sr_P + (y(i)-a0_P-a1_P.*x(i))^2;
end
%Define linear fit r^2
r_P= sqrt((St_P-Sr_P)/St_P)
r2_P=r_P^2
%Calculate alpha beta
alpha_P = 10^a0_P
beta_P = a1_P
F = alpha_P*(V.^beta_P);
%Plot graph
figure(1)
plot(V,W,'.') %plot raw data
xlabel('V')
ylabel('W')
title('Power Law Model')
hold on
plot(V,F,'linewidth',1.5,'color','r') %plot the data in non-linear
legend('Data', 'Power Law Model Graph') %Assign the graph
caption = sprintf('W = %f * V^{%f}', alpha_P, beta_P);
text(6,120, caption, 'FontSize', 12, 'Color', 'r' ); %text color and size
%Display the equation
%%