Project

Curve Fitting

clear all;
close all;
clc;

%Preparing the data
shdata=load(\'data_curve fitting\');
temp=shdata(:,1);
sh=shdata(:,2);

%Plotting original data
figure(1);
plot(temp,sh)
xlabel(\'Temperature [K]\');
ylabel(\'Specific Heat [KJ/Kmol-K]\');

%Curve fit1
%sh=a*T^2 + b*T + c
linear_sh=polyfit(temp,sh,2);
predicted_sh=polyval(linear_sh,temp);

%Compare curve fit with original data
hold on;
plot(temp,predicted_sh,\'color\',\'r\')
legend(\'Original data\',\'Linear curve fit\');

%Plotting original data
figure(2);
plot(temp,sh)
xlabel(\'Temperature [K]\');
ylabel(\'Specific Heat [KJ/Kmol-K]\');

%Curve fit2
%sh=a*T^3 + b*T^2 + cT + d
cubic_sh=polyfit(temp,sh,3);
predicted_sh=polyval(cubic_sh,temp);

%Compare curve fit with original data
hold on;
plot(temp,predicted_sh,\'color\',\'g\')
legend(\'Original data\',\'Cubic curve fit\');

2) In order to make the curve fit perfect, we need to increase the power of the polynomial equation which defines the specific heat values over a range of temperatures.

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.