Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a function in MATLAB which performs linear interpolation if two (x,y) data

ID: 3800392 • Letter: W

Question

Write a function in MATLAB which performs linear interpolation if two (x,y) data sets are entered or quadratic interpolation if three sets of data are entered. The function should be called “poly_int” and have three inputs: 1. the x data vector, 2. the y data vector, and 3. the x evaluation point. Use the “ifelse” or “switch, case, otherwise” control flow commands to determine which commands to run. Make sure to display appropriate messages if the sizes of the data sets don’t agree, if the size of the data sets are less than 2 or greater than 3, if the inputs are invalid, or if the evaluation point is outside of the range of the data sets.

Explanation / Answer

x = 0:pi/4:2*pi; v = sin(x); Define the query points to be a finer sampling over the range of x. xq = 0:pi/16:2*pi; Interpolate the function at the query points and plot the result. figure vq1 = interp1(x,v,xq); plot(x,v,'o',xq,vq1,':.'); xlim([0 2*pi]); title('(Default) Linear Interpolation');

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote