rect10_vallillo_HW02

rect10_vallillo_HW02 - % Homework Problem #1 clear;clc...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
% Homework Problem #1 clear;clc disp('Problem 1 - Interpolation: Answers') volume=1:6;pressure=[2494 1247 831 623 499 416];a=interp1(volume,pressure,3.8);b=interp1(volume,pressure,3.8,'spline');c=in terp1(pressure,volume,1000); %variable definitions fprintf('a) Using linear interpolation the estimated pressure at a volume of 3.8 cubic meters is %.3f kPa.\n',a) fprintf('b) Using cubic spine interpolation the estimated pressure at a volume of 3.8 cubic meters is %.3f kPa.\n',b) fprintf('c) Using linear interpolation the estimated volume at 1000 kPa is %.3f cubic meters.\n',c) % Homework Problem #2 disp('Problem 2 - Curve Fitting: Answer in Figure 1') % calculate the coefficients of 1st, 2nd, 3rd, and 4th order coef1=polyfit(volume,pressure,1); coef2=polyfit(volume,pressure,2); coef3=polyfit(volume,pressure,3); coef4=polyfit(volume,pressure,4); x=1:.2:6; y1=polyval(coef1,x);y2=polyval(coef2,x);y3=polyval(coef3,x);y4=polyval(coef4,x); figure(1) plot(volume,pressure,'o',x,y1,x,y2,x,y3,x,y4); title('Curve Fitting of Volume vs
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.
Ask a homework question - tutors are online