Project

Week 4 - Curve fitting

%curve fitting of temperature vs specific heatclear allclose allclc%load the data which contains variation of specific heat with temperaturetemp_cp=load('data');temperature=temp_cp(:,1);cp=temp_cp(:,2);%%curve fit%%cp=a*t^2+b*t+ccoeff=polyfit(temperature,cp,2);predicted_cp=polyval(coeff,temperature);%plotting the datafigure(1)title('Second Order Fit')hold onxlabel('Temperature [K]','color','r')ylabel('Specific Heat [KJ/Kg-K]','color','r')plot(temperature,cp,'linewidth',1,'color','g')plot(temperature,predicted_cp,'linewidth',1,'color','r')legend('Original data set','curve fit')grid on%using third order polynomialcoeff_3=polyfit(temperature,cp,3)predicted_cp1=polyval(coeff_3,temperature)figure(2)title('Third Order Fit')hold onplot(temperature,cp,'linewidth',1,'color','g')plot(temperature,predicted_cp1,'linewidth',1,'color','r')xlabel('Temperature [K]','color','r')ylabel('Specific Heat [KJ/Kg-K]','color','r')legend('Original data set','curve fit') 

To get more smooth curve fit we can use higher order polynomials or splitwise polynomials which means using differents polynomials for different 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.