using matlab please (write a new program not bult-in) 4. Write a function file w
ID: 3596189 • Letter: U
Question
using matlab please (write a new program not bult-in)
4. Write a function file with the following structure function scubicinterp (x,y, z) The function will take data points in arrays r and y and will return an array s containing the values of cubic spline interpolant evaluated at all of the points in the given array z There is a code outline on Canvas to help you with this implementation You may want to test your function with the following data: T 0.06 0.47 1.01 1.50 2.052.532.993.44 1.0499 1.32741.3588 1.2550 1.63222.55233.4462 3.6684 With this test data: (a) The spline coefficients are (a,'s in the first column, b,'s in the second, and so on): 0 0.7004 0.7946 0.4414 - 1.0499 1.3274 1.35880.24310. 1.2550 1.6322 2.5523 3.4462 0.0497 1.4059 2.2372 1.2310 -0.8614 -0.4061 1.0038 1.4618 0.2702 2.4575 0.2810 0.9592 0.2776 -0.8275 -1.9766 1.8204 (b) With that data, a few (r, S(r)) values of the interpolant include: (0.8,1.3893), (2.45, 2.3755), and (3.23,3.6253) (c) The plot of the interpolantExplanation / Answer
%Here is the code to perform the given tasks, do comment out if you have any doubt. Thumbs up if this helped!
%function to do the cubic interpolation
function s=cubicinterp(x,y,z)
s=spline(x,y,z);
end
%program to test the data
x=[0.06 0.47 1.01 1.50 2.05 2.53 2.99 3.44];
y=[1.0499 1.3274 1.3588 1.2550 1.6322 2.5523 3.4462 3.6684];
[breaks coefs] = unmkpp(spline(x,y)) %displays the coefficients of the cubic interpolation for each value of x
s=cubicinterp(x,y,[0.8 2.45 3.23]); %test for a few values of x
xx=[0.05:0.01:3.5]; %initialise values for x
yy=cubicinterp(x,y,xx); %interpolate values of y
plot(x,y,':',xx,yy); %plot the spline function we found
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.