Problem 1: Spline Interpolation To maximize the catch of bass in a lake, it is s
ID: 3920234 • Letter: P
Question
Problem 1: Spline Interpolation To maximize the catch of bass in a lake, it is suggested to throw the line to the depth of the thermocline layer. The characteristic feature of the thermocline layer is the sudden change in temperature. (Read textbook Ch 05.00C for the full story). Table 1 shows some measured temperature vs. depth data. In this problem, you will write MATLAB functions to implement quadratic spline interpolation and identify the depth of the thermocline Table 1 Temperature vs Depth for a Lake Temperature, y(C) 19.1 19.1 19 18.8 18.7 18.3 18.2 17.6 11.7 9.9 9.1 Depth, x(m) -4 -6 7 -9 10Explanation / Answer
Program :
syms x
disp('What type of Interpolation you seek');
g=input('enter 1 for 4th order and 2 for Quadratic');
depth=[0 -1 -2 -3 -4 -5 -6 -7 -8 -9 -10];
temp=[19.1 19.1 19 18.8 18.7 18.3 18.2 17.6 11.7 9.9 9.1];
if g==1
p=polyfit(depth,temp,4);
end
if g==2
p=polyfit(depth,temp,2);
end
y=0;
for i=1:length(p)
y=y+p(i)*x^(length(p)-i);
end
disp(y)
k=input('Enter a depth value x in the range -10 and 0 : ');
disp('Corresponding Temperature value is');
disp(subs(y,x,k));
y1=0;
y2=0;
r=polyfit(depth,temp,4);
q=polyfit(depth,temp,2);
for i=1:length(r)
y1=y1+r(i)*x^(length(r)-i);
end
for i=1:length(p)
y2=y2+q(i)*x^(length(q)-i);
end
plot(depth,temp,'r');
hold on
ezplot(y1,[-10,0])
hold on
ezplot(y2,[-10,0])