CURVE FITTING USING MATLAB
> Curve fit are helpful as they describe hoe your data changes mathematically.
> Below is the programs for curve fitting using MATLAB.
> In these programs our main motive is to predict the values of specific heat with respect to temperature to get a better fit.
>As we can analyse from the below written codes that linear fit has more error as compare to the cubic fit. What we understand from this is that as the order of degree in the function increases there are less chance of error i.e. we are going to get a much better curve.
>Although there are 4 quantities which helps us to measure the goodness of fit. These are as follows
1.The sum of squares due to error (SSE)
2.R-square
3.Adjusted R-square
4.Root mean squared error (RMSE)
CODES FOR LINEAR FIT:
clear all
close all
clc
% Loading the data
cp_data = load('data');
temperature = cp_data(:,1);
cp = cp_data(:,2);
% performing the curve fit for a linear equation
% cp = a*t+b
co_effs = polyfit(temperature,cp,1);
predicted_cp = polyval(co_effs,temperature);
%Comparing the curve fit by original data
plot(temperature,cp,'linewidth',3);
hold on ;
plot(temperature,predicted_cp,'linewidth',3,'r');
xlabel('TEMPERATURE[K]');
ylabel('SPECIFIC HEAT[KJ/K MOL-K]');
legend('Original curve','Curve fit');
Title('Curve fit for a linear function');
FIGURE1:
CODES FOR CUBIC FIT:
clear all
close all
clc
% Loading the data
cp_data = load('data');
temperature = cp_data(:,1);
cp = cp_data(:,2);
% performing the curve fit for a cubic polynomial function
% cp = a*t^3 + b*t^2 + c*t + d
co_effs = polyfit(temperature,cp,3);
predicted_cp = polyval(co_effs,temperature);
%Comparing the curve fit by original data
plot(temperature,cp,'linewidth',3);
hold on ;
plot(temperature,predicted_cp,'linewidth',3,'r');
xlabel('TEMPERATURE[K]');
ylabel('SPECIFIC HEAT[KJ/K MOL-K]');
legend('Original curve','Curve fit');
Title('Curve fit for a linear function');
FIGURE 2: