Matlab code needed for this problem. The data in table shown below is from Table
ID: 1862257 • Letter: M
Question
Matlab code needed for this problem.
The data in table shown below is from Tables A.1 and A.5 in Frank White, Fluid Mechanics. Using the not-a-knot cubic spline interpolant, estimate the surface tension of water gama, and the vapor pressure of water, pv, when T= 34 degree C, 68 degree C, 86 degree C, and 91 degree C. Present these results in a table using fprintf. At what temperature is the vapour pressure (mu) = 5 kPa? Print the result to the screen using fprintf. At jpg is not needed. In your opinion do you think linear interpolation is accurate enough, or is it a good idea to use spline interpolation? Answer in comments.Explanation / Answer
clear all;clc;close all
%data
T=[0:10:100];
ups=[0.0756 0.0742 0.0728 0.0712 0.0696 0.0679...
0.0663 0.0644 0.0626 0.0608 0.0589]; %surface tension, N/m
pv=[0.611 1.227 2.337 4.242 7.375 12.34 19.92...
31.16 47.35 70.11 101.3]; %vapor pressure, KPa
Ti=[34 68 86 91]; %interpolation points
%surface tension
ups_line=interp1(T,ups,Ti,'linear');
ups_spline=interp1(T,ups,Ti,'spline');
%vapor pressure
pv_line=interp1(T,pv,Ti,'linear');
pv_spline=interp1(T,pv,Ti,'spline');
%inverse interpolation for Temperature
T_pv_line=interp1(pv,T,1,'linear');
T_pv_spline=interp1(pv,T,1,'spline');
%print results
fprintf('Temp (C) upsilon (N/m) Pv (kPa) ')
fprintf(' linear spline linear spline ')
for i=1:numel(Ti)
fprintf('%5d %10.3f %12.3f %12.3f %12.3f ',Ti(i),...
ups_line(i),ups_spline(i),pv_line(i),pv_spline(i))
end
fprintf(' ')
fprintf('Inverse interpolation ')
fprintf('The vapor pressure of water = 5kPa at T=%5.2f C (linear) ',T_pv_line)
fprintf('The vapor pressure of water = 5kPa at T=%5.2f C (spline) ',T_pv_spline)
Temp (C) upsilon (N/m) Pv (kPa)
linear spline linear spline
34 0.071 0.071 5.495 5.317
68 0.065 0.065 28.912 28.561
86 0.062 0.062 61.006 60.101
91 0.061 0.061 73.229 72.818
Inverse interpolation
The vapor pressure of water = 5kPa at T= 6.31 C (linear)
The vapor pressure of water = 5kPa at T= 6.82 C (spline)
From the results, it seems like linear is pretty good, but not exact To try to answer the question, let's graph to be sure. and we see that there is some curvature in the trend, but the table points are finely spaced enough so that linear interpolation introduces very little error.
These tables are designed with a predetermined acceptable error level. Let's compute the relative error for pv, as this has the most curvature Consider the spline interpolation to be "true". We about a 3% error
ea=abs((pv_spline-pv_line)./pv_spline)*100
ea =
3.3453 1.2277 1.5057 0.5641
%plot
tt=linspace(min(T),max(T));
upup=interp1(T,ups,tt,'spline');
pvpv=interp1(T,pv,tt,'spline');
figure
hold on
plot(tt,upup,'r')
plot(T,ups,'rd','markerfacecolor','y')
title('surface tension')
xlabel('surface tension upsilon [N/m]')
ylabel('temperature T [circC]')
figure
hold on
plot(tt,pvpv,'k')
plot(T,pv,'kd','markerfacecolor','c')
title('vapor pressure')
xlabel('vapor pressure p_v [kPa]')
ylabel('temperature T [circC]')