Question

In: Computer Science

Write a Matlab function called: lin_interp. The function should have three inputs: the two original data...

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.

Solutions

Expert Solution

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.


Related Solutions

1) a) Write a MATLAB function called Area1 having two inputs, r and N, and an...
1) a) Write a MATLAB function called Area1 having two inputs, r and N, and an output, A1. The output A1 should be the area under a curve, f(x), for x starting at x_start and ending at x_end. The input r should be a vector (array) having x_start and x_end as its two elements. The input N should be an integer equal to the number of equallength sub-intervals in which the interval from x_start to x_end should be divided. Here,...
Write a MATLAB function named myaccel that accepts three inputs and has a single output. Inputs:...
Write a MATLAB function named myaccel that accepts three inputs and has a single output. Inputs: a list of time values a list of position values a single time value. Output: a single number which is obtained by numerically differentiating position with respect to time twice (forward difference method) and then interpolating the results based on the third input. Example: time=0:10; position=time.^3; myaccel(time,position,2.8) % should return 22.8
#Write a function called solve_right_triangle. The function #solve_right_triangle should have three parameters: opposite, #adjacent, and use_degrees....
#Write a function called solve_right_triangle. The function #solve_right_triangle should have three parameters: opposite, #adjacent, and use_degrees. opposite and adjacent will be #floats, and use_degrees will be a boolean. use_degrees #should be a keyword parameter, and it should have a #default value of False. # #The function should return a tuple containing the #hypotenuse and angle of the right triangle (in that order). #If use_degrees is False, the angle should be in radians. #If use_degrees is True, the angle should be...
Write a function called tokenizeTelNum that inputs a telephone number as a string in the form...
Write a function called tokenizeTelNum that inputs a telephone number as a string in the form (555) 555-5555. The function should use the function strok to extract the area code as a token, the first three digits of the phone number as a token and the last four digits of the phone number as a token. The seven digits of the phone number should be concatenated into one string. The function should convert the area code string to int and...
Write a Matlab/SciLab function that accepts inputs as degrees and computes the equivalent within the interval...
Write a Matlab/SciLab function that accepts inputs as degrees and computes the equivalent within the interval 0 to 360. function de=equivalent(d) For example, equivalent(540) = 180 equivalent(-30) = 330
Write a MATLAB function, called arbpoly, that computes a polynomial arbitrary nth degree. The function will...
Write a MATLAB function, called arbpoly, that computes a polynomial arbitrary nth degree. The function will take 2 inputs: 1) the first input will be a row vector, c, containing the coefficients of the polynomial, starting with the coefficient of the highest - degree term; 2) the second input will be a scalar, x, which is a real number at which the polynomial will be evaluated. The function's only output, y, will be the scalar value of the polynomial computed...
A. Write a function in MATLAB called findTranspose that takes in as input any matrix or...
A. Write a function in MATLAB called findTranspose that takes in as input any matrix or any vector and simply returns back the transpose of that input. You can always verify your answer by using the inbuilt transpose function in MATLAB, however, you cannot use the transpose function directly when writing your code. Here is the starter code that we are providing to help you get started %x is the input vector or matrix. You can find the %size that...
#Write a function called wish_list. wish_list should have #four parameters, in this order: # # -...
#Write a function called wish_list. wish_list should have #four parameters, in this order: # # - a list of strings, representing a list of items on a # wish list # - a string, representing a particular item # - a float, representing the cost of this item # - a float, representing your budget # #If the item is on the list and you can afford it (cost is #less than or equal to budget), return the string, #"You...
Write a single MATLAB function called numdiff, saved in a file called numdiff.m. Submit that single...
Write a single MATLAB function called numdiff, saved in a file called numdiff.m. Submit that single file here in Canvas. To make grading easier, please do the following: • Close your function with "end". • Don't have your function print anything to the console; just return the output. To accomplish this: o Put a semicolon ";" at the end of each statement. o Put a percent "%" before each disp or fprintf statement. The function numdiff should take the following...
Using Matlab Write a function, called digits_function that is able to calculate the number of digits...
Using Matlab Write a function, called digits_function that is able to calculate the number of digits and the multiplication of the digits. The input of this function is N (entered number) and the outputs are number_digits and sum_digits.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT