Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Creating a user-defined function Write a user-defined MATLAB function named P

ID: 3757368 • Letter: 1

Question

1. Creating a user-defined function Write a user-defined MATLAB function named PBTask4p1_f.m for the following math function with x the input argument and y the output: y(x)-0.8r-132-5x The function should work for x being a scalar or a vector. Write a script file named PBTask4p1.m to a) Use the function to calculate y(-5) and y(4) and display the results in command window b) Use the function to make a plot of the function y(x) for -5 sx s 5. Label the x-axis and y-axis of the plot like the one as follows 100

Explanation / Answer

Answer :

Step 1:  create a file called PBTask4p1_f.m and save the following function code into the file
function y = PBTask4p1_f(x)
y = 0.8 * x.^4 - 13 * x.^2 - 5*x;
end

Step 2: create file named PBTask4p1.m and copy the following code
y3 = PBTask4p1_f(-5)
y5 = PBTask4p1_f(4)

x = -5:0.1:5;
y = PBTask4p1_f(x);
figure
plot(x, y);
xlabel('Input: x')
ylabel('Output: y')
xlim([-5 5]);
ylim([-100 200]);

Now run the file PBTask4p1.m to get the values of y(-5), y(4)