HW_8 - n=length(x); Sx=0; Sy=0; Sx2=0; Sx3=0; Sx4=0; Sxy=0;...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Homework#8 2) Script file titled Problem2.m fid=fopen( 'heat_capacity.txt' , 'rt' ); headings1=fgetl(fid); d=fscanf(fid, '%f' ); d=reshape(d,[2 52])'; x=d(:,1) y=d(:,2) [a0,a1,a2]=PolynomialFit(x,y); fity=zeros(size(x)); n=length(x); for i=1:n fity(i)=a2*x(i)^2+a1*x(i)+a0; end plot(x,y, 'x' ,x,fity, 'k-' ) grid on ; xlabel( 'T(K)' ) ylabel( 'Cp(KJ/Kg-K)' ) title( 'Heat Capacity vs. Temperature' ) legend( 'x : data' , 'solidline : fitted curve' ); Function file titled PolynomialFit.m function [a0,a1,a2]=PolynomialFit(x,y)
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: n=length(x); Sx=0; Sy=0; Sx2=0; Sx3=0; Sx4=0; Sxy=0; Sx2y=0; for i=1:n Sx=Sx+x(i); Sy=Sy+y(i); Sx2=Sx2+x(i)*x(i); Sx3=Sx3+x(i)^3; Sx4=Sx4+x(i)^4; Sxy=Sxy+x(i)*y(i); Sx2y=Sx2y+x(i)^2*y(i); end A=[n Sx Sx2; Sx Sx2 Sx3; Sx2 Sx3 Sx4]; b=[Sy;Sxy;Sx2y]; a=A\b; a0=a(1,:); a1=a(2,:); a2=a(3,:); 1000 2000 3000 4000 5000 6000 0.7 0.8 0.9 1 1.1 1.2 1.3 1.4 1.5 1.6 T(K) Cp(KJ/Kg-K) Heat Capacity vs. Temperature x : data solidline : fitted curve...
View Full Document

Page1 / 2

HW_8 - n=length(x); Sx=0; Sy=0; Sx2=0; Sx3=0; Sx4=0; Sxy=0;...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online