Question: Create a function that computes the nearest neighbor constant interpolation of n given points. Write the function in such a way that it computes p

Create a function that computes the nearest neighbor constant interpolation of n given points. Write the function in such a way that it computes p points interpolating any two data points, and returns vectors containing the coordinates corresponding to the interpolation of all points.

Edit the following MATLAB code below:

function [x,y] = piecewise_const(xs,ys,x_query)

% A function that provides a piecewise constant interpolation for the `x_query` points.

% Input: xs, ys -- row vector of size n, x_query -- row vector of query points

% (can be arbitrary size) We assume xs is sorted.

% Note that all we need to do is to "look up" for the nearest

% neighbors. Also watch out for the shapes of xs and ys. Finally, consider using

% matlab's min function which has the option to also return indices. Matlab's repmat

% is also quite useful.

% Your code below

end

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Finance Questions!