MATLAB QUESTION. Using the given function f(x,y) complete the following tasks. Y
ID: 3699999 • Letter: M
Question
MATLAB QUESTION. Using the given function f(x,y) complete the following tasks. You need to create 2 files: 1 script and 1 user-defined function. Remember to comment your code.
f(x,y) = x4y-x3-20x2+6xy+20
A. User-defined function
i. the user defined function will have 3 inputs, the anonymous function, the value of y, and the range for the plot.
ii. plot the anonymous function
iii. Turn the grid on for the plot.
iv. Label the plot properly.
B. Script file.
i. Creat an anonymous function with x and y as variables.
ii. set y = y
iii. call the user defined function to plot the anonymous function from x = -3 to x = 3
iv. Use a function-of-function(fzero) to determine at least one of the roots for the anonymous function. Analyze the plot to determine your initial value or range.
v. Using a function-of-function determine the global minimum. Analyze the plot to get a general idea where it is.
(DONT FOR GET TO EXPLAIN CODE PLEASE)
Explanation / Answer
A)
function p = plotF(fun, y, range)
[x,y] = meshgrid(range);
z = fun(x,y)
surf(x,y,z)
xlabel('x')
ylabel('y')
zlabel('z')
title('Plot of the anonymous Function')
B)
fun = @(x,y)x^4*y-x^3-20*x^2+6*x*y+20;
y=y
plotF(@(x,y)(fun(x,y)),y,linspace(-3,3,1))
roots = fzero(@(x,y)(fun(x,y)),0)
[xMin,fVal] = fminbnd(@(x,y)(fun(x,y)),0,10);
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.