CURVE FITTING USING MATLAB FOR LINEAR AND CUBIC FUNCTION
AIM: To find the function of curve fitting using the matlab simulation and to obtain the best curve fitting by using spitting the curve.
THEORY: Curve fitting is basically used for us the predict how it will be in the future.Curve fitting is the process of constructing curve and mathematical function.Its gives as the best fit to the given values.We can assume the fit curve gives us the prediction values only and not the exact values.It examines between one or two values.It gives us the responsible variable values.There are lot of opperation you can perform in the curve fit for a linear,non-linear,surface,etc.
PROBLEM:
CURVE FITTING FOR THE LINEAR AND CUBIC PLOYNOMIAL
close all
clear all
clc
%data value
cp_data=load('data');
temp=cp_data(:,1);
cp=cp_data(:,2);
%curve fit
co_eff=polyfit(temp,cp,1);
pre_cp=polyval(co_eff,temp);
co_eff_1=polyfit(temp,cp,3);
pre_cp1=polyval(co_eff_1,temp);
%comparing the values and plot
plot(temp,cp,'linewidth',3)
hold on
plot(temp,pre_cp,'linewidth',1,'color','r')
hold on
plot(temp,pre_cp1,'linewidth',1,'color','g')
xlabel('Temperature[k]')
ylabel('Specific Heat [K]/Kmol-KJ')
title('curve fitting')
legend('Orginal Data Set','Curve Fit')
mean=(sum(cp)/length(cp));
ssr1=sum((pre_cp-mean).^2);
ssr2=sum((pre_cp1-mean).^2);
sse1=sum((cp-pre_cp).^2);
sse2=sum((cp-pre_cp1).^2);
sst1=ssr1+sse1;
sst2=ssr2+sse2;
rsquare1=ssr1/sst1;
rsquare2=ssr2/sst2;
PLOT:
SPLITWISE POLYNOMIAL PROGRAM:
close all
clear all
clc
%data value
cp_data=load('data');
temp=cp_data(:,1);
cp=cp_data(:,2);
a=1;
b=400;
for i=1:8;
co_eff = polyfit(temp(a:b),cp(a:b),2);
pre_cp(a:b) = polyval(co_eff,temp(a:b));
a=b+1;
b=b+400;
end
plot(temp,cp);
hold on
plot(temp,pre_cp)
PLOT:
FORMULA: `mean=(sum(cp)/length(cp))`
`ssr=sum((Pre_cp-mean)^2)`
sse=sum((cp-pre_cp)^2)`
sst=ssr+sse`R^2=(ssr)/(sse)
RESULTS: Using matlab we are able to find out the curve fitting for linear and cubic polynomial and we are also able to make the best fit using the splitwise.We also found the second variable gives us the best fit compared to the linear and cubic polynomial.