Problem 3: Linear Spline in Matlab. Preparation Read through the rest of \"A Pra
ID: 3807824 • Letter: P
Question
Problem 3: Linear Spline in Matlab. Preparation Read through the rest of "A Practical Introduction to Matlab" by Gock- enbach, at the web site http://www.math.mtu.edu/ msgocken/intro/intro.pdf Your task. Write a Matlab function that computes the linear spline interpolation for a given data set. You might need to take a look at the file cspline_eval.m for some hints. Name your Matlab function lspline. This can be defined in the file lspline.m, which should begin with: function ls lspline (t,y,x) lspline computes the linear spline Inputs t: vector contains the knots y: vector, contains the interpolating values at knots t x: vector contains points where t 1spline function he should be evaluated and plotted Output: ls: vector contains the values of lspline at points x Use your Matlab function lspline on the given data set in Problem 2, plot the linear spline for the interval 1.2, 2.2 what to hand in: Hand in the Matlab file lspline.m, the script file, and your plots.Explanation / Answer
Solution:
Executable Code:
function ls=lspline(t,y,x)
len=length(x);
for j=1:len
for k=1:length(t)
if x(j)<t(k)
break;
end
end
i=k-1;
ls(j)=y(i)+(x(j)-t(i))*(y(i+1)-y(i))/(t(i+1)-t(i));
end
return
end
t=[1.2 1.5 1.6 2.0 2.2]
y=[0.4275 1.139 0.8736 -0.9751 -0.1536]
x=[1.2:0.1:2.1]
ls=lspline(t,y,x);
ls
Output:
ls =
Columns 1 through 7:
0.427500 0.664667 0.901833 1.139000 0.873600 0.411425 -0.050750
Columns 8 through 10:
-0.512925 -0.975100 -0.564350
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.