Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Curve fitting is the process of constructing a curve, or mathematical function, that has the
best fir to a series of data points, possibly subject to constraints. Curve fitting can involve either
interpolation, where an exact fit to the data is required or smoothing, in which a “smooth”
function is constructed that approximately fits the data.
A related topic is regression analysis, which focuses more on questions of statistical
inference such as how much uncertainty is present in a curve that is fit to data observed with
random errors. Fitted curves can be used as an aid for data visualization, to infer values of a
function where no data are available, and to summarize the relationships among two or more
variables. Extrapolation refers to the use of a fitted curve beyond the range of the observed data
and is subject to a degree of uncertainty since it may reflect the method used to construct the
curve as much as it reflects the observed data.
There are two general approaches for curve fitting. First is that data exhibit a significant
degree of scatter. The strategy is to derive a single curve that represents the general trend of the
data. Second is that the data is very precise. The strategy is to pass a curve or a series of curves
through each of the points.
Commonly, in engineering two types of applications are encountered. First is trend
analysis. Predicting values od dependent variable , may include extrapolation beyond data points
or interpolation between data points. Second is hypothesis testing which is comparing existing
mathematical model with measured data.
1
1. Linear Model
Matlab Code
load data.mat
format long;
2
Figure 1 shows scaled graph pf linear model curve
3
Figure 3 shows the values obtained from linear model
4
2. Power Law Model
Matlab Code
load data.mat
format long;
%retrieval of data from data.mat and assigning variables respectively
distance=distance(1,:);
receivedpower = receivedpower(1,:);
log10_distance= log10(distance);
log10_receivedpower= log10(receivedpower);
n=length(log10_distance);
m=length(log10_receivedpower);
total_d=sum(log10_distance);
total_rp=sum(log10_receivedpower);
mean_d=total_d/n;
mean_rp=total_rp/m;
square_d=sum(log10_distance.^2);
square_rp=sum(log10_receivedpower.^2);
sum_total=sum(log10_distance.*log10_receivedpower);
a1=((n*sum_total)-(total_d*total_rp))/((n*square_d)-total_d^2);
a0=(mean_rp-a1*mean_d);
B2=a1;
A2=10^a0;
y=A2*distance.^B2;
figure(2)
scatter(distance, receivedpower)
hold on
plot(distance,y)
hold off
title('Power Law Model')
xlabel('distance (m)');
ylabel('receivedpower (W)');
a1
a0
ymean=mean(log10_receivedpower);
St=sum((log10_receivedpower-ymean).^2)
Sr=sum((log10_receivedpower-a0-a1*log10_distance).^2)
rsquare=(St-Sr)/St
a=10^a0;
b=a1;
a
b
5
Figure 5 shows the graph of power law model without scaling
6
Figure 7 shows the scaled down graph of power law model.
Figure 8 shows the values obtained from the power law model curve
7
Figure 9 shows the values of coefficients obtained from power law model
From Figure 9 we can see that the distance between the curve and the real data is small compared to
other type of curve. Hence power law model is preferred.
8
3. Saturation Growth Rate Model
Matlab Code
load data.mat
format long;
%retrieval of data from data.mat and assigning variables respectively
distance=distance(1,:);
receivedpower = receivedpower(1,:);
one_distance=1./distance;
one_receivedpower=1./receivedpower;
n=length(one_distance);
m=length(one_receivedpower);
total_d=sum(one_distance);
total_rp=sum(one_receivedpower);
mean_d=total_d/n;
mean_rp=total_rp/m;
square_d=sum(one_distance.^2);
square_rp=sum(one_receivedpower.^2);
sum_total=sum(one_distance.*one_receivedpower);
a1=((n*sum_total)-(total_d*total_rp))/((n*square_d)-total_d^2);
a0=(mean_rp-a1*mean_d);
a1
a0
A3=1/a0;
B3=a1*A3;
y=A3*(distance./(B3+distance));
ymean=mean(one_receivedpower);
St=sum((one_receivedpower-ymean).^2)
Sr=sum((one_receivedpower-a0-a1*one_distance).^2)
rsquare=(St-Sr)/St
figure(3)
scatter(distance, receivedpower)
hold on
plot(distance,y)
hold off
title('Saturation Growth Rate Model')
xlabel('distance (m)');
ylabel('receivedpower (W)');
a=1/a0;
b=a*a1;
a
b
9
Figure 10 shows the curve of saturation growth rate model
Figure 11 shows the scaled down curve of saturation growth rate model
10
Figure 12 shows the results obtained from saturation growth rate model
Figure 13 shows the value of coefficients obtained from saturation growth rate model.
11
Discussion
For all the three selected models a1 and a0 had been calculated using the formula:
𝑛∑𝑥𝑖 𝑦ⅈ − ∑𝑥𝑖 ∑𝑦ⅈ
𝑎1 =
𝑛𝛴𝑥𝑖2 − (𝛴𝑥𝑖 )2
𝑎0 = 𝑦̅ − 𝑎1 𝑥̅
Where 𝑦̅ and 𝑥̅ are mean of y values and x values respectively.
Calculation of 𝒓𝟐
𝑟 2 has been calculated as a measure of the goodness of fit of the curve.
𝑛 𝑛 𝑛
𝑆𝑡 = ∑(𝑦𝑖 − 𝑦̄ ) 2
𝑆𝑟 = ∑ 𝑒𝑖2 = ∑(𝑦𝑖 − 𝑎0 − 𝑎1 𝑥𝑖 )2
𝑖=1 𝑖=1 𝑖=1
St is the total sum of the squares around the mean for the dependent variable, y.
Sr is the sum of the squares of residuals around the regression line.
St - Sr quantifies the improvement or error reduction due to describing data in terms of a straight
line rather than as an average value. Hence,
𝑆𝑡 − 𝑆𝑟
𝑟2 =
𝑆𝑡
𝑟 2 is known as the coefficient of determination.
1. Linear model
Equation for linear model is 𝑦 = 𝑎𝑥 + 𝑏.
Since 𝑎1 and 𝑎0 has been related to the linear model equation to obtain the values of a and b.
The general equation is y=a0+a1x . Hence 𝑎0 = 𝑏 𝑎𝑛𝑑 𝑎1 = 𝑎
𝑎 = −6 ⋅ 35 × 10−6
𝑏 = 0.0043
The value of 𝑟 2 calculated is 0.0416.
𝑦 == −6 ⋅ 35 × 10−6 𝑥 + 0.0043
12
2. Power Law Model
Equation for power law model is 𝑦 = 𝑎𝑥 𝑏 .
𝑎1 and 𝑎0 has been related to the power law model equation to obtain the values of a and b.
The general equation is 𝑙𝑜𝑔 𝑦 = 𝑎0 + 𝑎1 𝑙𝑜𝑔 𝑥. Hence 𝑎 = 10𝑎0 𝑎𝑛𝑑 𝑏 = 𝑎1
𝑎 = 30.221
𝑏 = −2.396
The value of 𝑟 2 calculated is 0.9244.
𝑦 = 30.221𝑥 −2.396
3. Saturation Growth Rate model.
𝑥
Equation for saturation growth rate model is 𝑦 = 𝑎 𝑏+𝑥.
𝑎1 and 𝑎0 has been related to the power law model equation to obtain the values of a and b.
1 1
The general equation is 𝑦 = 𝑎0 + 𝑎1 𝑥. Hence 𝑎 = 1⁄𝑎0 𝑎𝑛𝑑 𝑏 = 𝑎1 𝑎
𝑎 = 4.604 × 10−6
𝑏 = −33.374
The value of 𝑟 2 calculated is 0.0735.
𝑥
𝑦 = 4.604 × 10−6
−33.374 + 𝑥
13