Here is Code:
function y=natural_cubic_spline_interp(x1,y1,x)
%x1=independent variable;x2=dependent variable;x=value at which we
have to
%find the dependent variable;y=corresponding value of dependent
variable at x;
y = spline(x1,y1,x);
end
clear all
close all
z=[-12 -32 -52 -72 -92 -130 -180 -230 -280 -330];
T=[15.31 15.31 15.32 15.32 15.32 15.22 15.14 14.19 13.31 12.9];
depth=[-330:2:-10];
for i=1:length(depth)
temp_LPI(i)=lagrange_interp(z,T,depth(i));
end
hold on
plot(z,T,'*')
plot(depth,temp_LPI,'b')
for i=1:length(depth)
temp_NDD(i)=newtondivdiff_interp(z,T,depth(i));
end
plot(depth,temp_NDD,'--g')
for i=1:length(depth)
temp_nCS(i)=natural_cubic_spline_interp(z,T,depth(i));
end
plot(depth,temp_nCS,'k')
title('Depth Vs. Temperature plot')
xlabel('Depth in meter')
ylabel('Temperature in degree c')
legend('Nodes','Lagrange','Newton','Cubic
Spline','Location','best')
temp_LP=lagrange_interp(depth, temp_LPI,-150);
fprintf('\nThe temperature value at z=-150 m using Lagrange
interpolation is %f \n',temp_LP)
temp_ND=newtondivdiff_interp(depth, temp_NDD,-150);
fprintf('\nThe temperature value at z=-150 m using Newton
interpolation is %f \n',temp_ND)
temp_sp=natural_cubic_spline_interp(depth, temp_nCS,-150);
fprintf('\nThe temperature value at z=-150 m using Cubic Spline
interpolation is %f \n',temp_sp)
)10 12 32-5272-92130 180 230280330 temperature, T (°C) 15.3 15.2915.28 15.27 15.2615.22 15.1414.19 13.3112.9 knots index, i depth, z (m) 3 6i Table 1: Temperature of seawater in the upper layer of th...
node index, i 2 3 0 depth, z (m) 12 32 -52 -72 92 -130 -180 -230 -280 -330 temperature, T (C) 15.3 15.29 15.28 15.27 15.26 15.22 15.14 14.19 13.31 12.9 Table 1: Temperature of seawater in the upper ocean surface layer Problem 4 (hand-calculation): Consider the seawater temperature data in table 1 to estimate the ternperature at depth z = 150 m. Use Newton polynomials with the following nodes (a) Nodes i = 3 and 4. (b) Nodes...