In: Computer Science
Write a Matlab function called: lin_interp. The function should have three inputs: the two original data arrays (call them x and f), and the array you would like to interpolate to (call it xstar). The function should have one output: the interpolated array ( call it fstar). The function should be able to interpolate x and f onto xstar using linear interpolation and give the result as fstar. The function may not use any intrinsic functions except length.
function lin_interp[fstar] = mylin_interp(x,f,xstar)
fstar = interp1(x, v, xstar, 'linear');
plot(fstar,xstar)
end
x = [10, 5, 2.5, 1.25, 0.625, 0.312, 0.156,0];
v = [41564.9, 21531.9, 15086.9, 9249, 3175.9, 1781.9, 1320.9, 182.9];
xstar = [1308.9, 2514.9, 4797.9];
function [x1,...,xN] = m
function lin_interp = lin_interp(x,f,xstar)
fstar = interpn(x,v,xstar,'linear')
end
yfun(y1,...,yC) declares a function named myfun that accepts inputs x1,...,xM and returns outputs x1,...,xN. This declaration statement must be the first executable line of the function. Valid function names begin with an alphabetic character, and can contain letters, numbers, or underscores.
save your function:
In a function file which contains only function definitions. The
name of the file must match the name of the first function in the
file.
In a script file which contains commands and function definitions.
Functions must be at the end of the file. Script files cannot have
the same name as a function in the file
Files can include multiple local functions or nested functions. For
readability, use the end keyword to indicate the end of each
function in a file.
Interpolation is a technique for adding new data points within a
range
of a set of known data points.
You can use interpolation to fill-in missing data,
smooth existing data, make predictions, and more.