Project

curve fitting

clear all
close all
clc

%data
cp=load(\'data\');
temperature = cp(:,1);
specific_heat= cp(:,2);

 %curvefit for a linear polynomial 
 co_efficients = polyfit(temperature,specific_heat,1);
 Predicted_values = polyval(co_efficients,temperature);
 
 %plotting
 figure(1)
 hold on
 plot(temperature,specific_heat,\'linewidth\',3)
 xlabel(\'temperature\');
 ylabel(\'specific_heat\');
 plot(temperature,Predicted_values,\'linewidth\',3,\'color\',\'r\')
 legend(\'original_data\',\'Predicted_values\')

 %error
 error=(specific_heat-Predicted_values)
 err= max(error);
 disp(err)
 
 
 
 %curvefit for a cubic polynomial 
 co_efficients = polyfit(temperature,specific_heat,3);
 Predicted_valuescubic = polyval(co_efficients,temperature);
 error_1=(specific_heat-Predicted_valuescubic)
 err1= max(error);
 disp(err)
 
 %plotting
 figure(2)
 hold on
 plot(temperature,specific_heat,\'linewidth\',3)
 xlabel(\'temperature\');
 ylabel(\'specific_heat\');

 %comparison curve between original and predicted values
 plot(temperature,Predicted_valuescubic,\'linewidth\',3,\'color\',\'r\')
 legend(\'original_data\',\'Predicted_valuescubic\')
 

 

Error was calculated to be 27.9.

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.