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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started