curve fitting
curve fitting
In this assignment ihave tried to fit the specific heat capacity value for different temp range using cubic ploynimal equation
close all
clear all
clc
% curve fitting of cp
cp_vs_temp=load('data');
temp=cp_vs_temp(:,2);
cp=cp_vs_temp(:,1);
%curve fit
coeff=polyfit(temp,cp,3);
predicted_cp=polyval(coeff,temp);
E=predicted_cp-cp;
sse=0;
for i=1:length(E)
sse=sse+E(i)^2;
end
%comparing predicted and actual value
hold on
plot(temp,cp,'linewidth',3,'color','r')
plot(temp,predicted_cp,'linewidth',2,'color','b')
xlabel('kelvin')
ylabel('joules/kelvin')
legend('actual','predicted')
the data contains the values of the temp vs cp
firstcolumn is the cp ,the second column is the temprature value
then using the polyfit command we are predcting the coefficents of the polynomial equation
then by the polyval command we are getting the values of cp
making aplot to visually see the curvefit made by the polyfit command
fitness of the curve fit
the fitness of the curve is measured in terms of sumof squared error(least square method)
this value represents the fitnesss of the cure fit
ways to increase the fitness
1)is to increase the number of coefficients if the polynomial(increase the order of the ploynomial)
this what happens to sse if increase order of the polynomial to 5
the drop in the sse is significant
curve fit
error defection
2)is using multiple intervals to make the curve fit
in this method we find, where the error values are shooting up when one curve is used
for temp range 950-1050 curve(1)
1050-1200 cuve(2)
1200-1300 curve(3)
such type of fit can be made
close all
clear all
clc
% curve fitting of cp
cp_vs_temp=load('data');
temp=cp_vs_temp(:,2);
cp=cp_vs_temp(:,1);
%curve fit (curve 1)
temp1=cp_vs_temp(1:380,2);
cp1=cp_vs_temp(1:380,1);
coeff1=polyfit(temp1,cp1,3);
predicted_cp1=polyval(coeff1,temp1);
sse=0;
E1=predicted_cp1-cp1;
for i=1:length(E1)
sse=sse+(E1(i)^2);
end
%curve 2
temp2=cp_vs_temp(380:1573,2);
cp2=cp_vs_temp(380:1573,1);
coeff2=polyfit(temp2,cp2,3);
predicted_cp2=polyval(coeff2,temp2);
E2=predicted_cp2-cp2;
for i=1:length(E2)
sse=sse+(E2(i)^2);
end
%curve 3
temp3=cp_vs_temp(1573:3200,2);
cp3=cp_vs_temp(1573:3200,1);
coeff3=polyfit(temp3,cp3,3);
predicted_cp3=polyval(coeff3,temp3);
E3=predicted_cp3-cp3;
for i=1:length(E3)
sse=sse+(E3(i)^2);
end
%comparing predicted and actual value
hold on
plot(temp,cp,'linewidth',5,'color','r')
plot(temp1,predicted_cp1,'linewidth',2,'color','b')
plot(temp2,predicted_cp2,'linewidth',2,'color','y')
plot(temp3,predicted_cp3,'linewidth',2,'color','r')
axis([900 1400 0 3500])
xlabel('kelvin')
ylabel('joules/kelvin')
the sse value drops
the error deflection also reduces