Project

curve fitting matlab

clear all
close all
clc

cp_data=load(\\\'data\\\');
 
temp=cp_data(:,1);
cp=cp_data(:,2);


co_eff=polyfit(temp,cp,1);
pred_cp=polyval(co_eff,temp);

figure(1)
hold on
plot(temp,pred_cp,\\\'linewidth\\\',2,\\\'color\\\',\\\'b\\\')
plot(temp,cp,\\\'linewidth\\\',2,\\\'color\\\',\\\'r\\\')
xlabel(\\\'TEMPERATURE\\\')
ylabel(\\\'SPECIFIC HEAT\\\')
legend(\\\'orginal data\\\',\\\'predicted cp\\\')


error=(cp-pred_cp);
err=max(error);
disp(err)

%loading the data of specific heat and temperature
%curve fitting using cubic polynomial

cp_data=load(\\\'data\\\');
 
temp=cp_data(:,1);
cp=cp_data(:,2);

co_eff=polyfit(temp,cp,3);
pred_cp=polyval(co_eff,temp);

figure(2)
hold on
plot(temp,pred_cp,\\\'linewidth\\\',2,\\\'color\\\',\\\'b\\\')
plot(temp,cp,\\\'linewidth\\\',2,\\\'color\\\',\\\'r\\\')
xlabel(\\\'TEMPERATURE\\\')
ylabel(\\\'SPECIFIC HEAT\\\')
legend(\\\'orginal data\\\',\\\'predicted cp\\\')


error=(cp-pred_cp);
err=max(error);
disp(err)


%to get less error, dividing the data into 4 divisions
%dividion 1 (300-1100)

cp1=cp(1:800);
temp1=temp(1:800);

co_eff1=polyfit(temp1,cp1,1);
pred_cp1=polyval(co_eff1,temp1);

figure(3)
hold on
plot(temp1,cp1,\\\'linewidth\\\',2,\\\'color\\\',\\\'b\\\')
plot(temp1,pred_cp1,\\\'linewidth\\\',2,\\\'color\\\',\\\'r\\\')
xlabel(\\\'TEMPERATURE\\\') 
ylabel(\\\'SPECIFIC HEAT\\\')
legend(\\\'orginal value1\\\',\\\'predicted value 1\\\')

error1=(cp1-pred_cp1);
err1=max(error1);
disp(err1);

cp2=cp(1:600);
temp2=temp(1:600);

co_eff2=polyfit(temp2,cp2,1);
pred_cp2=polyval(co_eff2,temp2);

figure(4)
hold on
plot(temp2,cp2,\\\'linewidth\\\',2,\\\'color\\\',\\\'b\\\')
plot(temp2,pred_cp2,\\\'linewidth\\\',2,\\\'color\\\',\\\'r\\\')
xlabel(\\\'TEMPERATURE\\\') 
ylabel(\\\'SPECIFIC HEAT\\\')
legend(\\\'orginal value2\\\',\\\'predicted value 2\\\')

error2=(cp2-pred_cp2);
err2=max(error2);
disp(err2)
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.