Question: Write (and demonstrate) a MATLAB function m-file that meets the following requirements: a. Has three input arguments (in order): an initial x value, a final
Write (and demonstrate) a MATLAB function m-file that meets the following requirements:
a. Has three input arguments (in order): an initial x value, a final x value, and a function handle (e.g. to an anonymous function).
b. Has two output arguments (in order): an x vector, and a y vector.
c. If any of the three inputs is not provided, print an error message with the error function. Hint: Check if the number of input arguments is less than 3.
d. If the initial x value is less than the final x value, generate an x vector with evenly spaced values between the initial and final values with an increment of 0.1.
e. If the initial x value is greater than the final x value, generate an x vector with evenly spaced values between the initial and final values with an increment of -0.1.
f. If the initial x value is equal to the final x value, generate an x vector containing only that value. Also, use disp and num2str to print a message stating that the x vector will only contain a single number: (display the number here).
g. Generate the y vector by calling the inputted function handle with the generated x vector.
h. For your submission, demonstrate your function by calling it with two sets of input arguments that go through different branches of your code. Include a plot of the outputted y vs. x vectors for one of your sets of inputs. Tip: You can create a function handle to an existing MATLAB function like this: handle = @sin;
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
