Question

1) Create a matlab function that calculates: for Name your function TwoVarFunc : The inputs should...

1) Create a matlab function that calculates:

bf90eb38-b1f8-40ea-bd26-853dce5268b2.jpe

for

5bd2621b-75ef-414e-8717-7de938d2b5e4.jpe

Name your function TwoVarFunc :

The inputs should be in the same order:

  • xmin
  • xmax
  • ymin
  • ymax
  • N: n is the number of elements in the vector x and y

The ouputs should be in the same order:

  • f_xy: is the calculated array f(x,y)
  • f_xyMAX: should be the the maximum value of the function f(x,y).

Hint: to create vectors x and y look up the matlab built-in function linspace()

Hint 2: To get the maximum value in f_xy use the built-in function max()

Code to call function:

[f_xy,f_xyMAX] = TwoVarFunc(-4,4,-5,5,100)

2)

Using the function in Problem 1, calculate:

4bd664e1-46f6-4ccc-aad3-3b2d5c5c3d0c.jpe

for : c2d9b0ed-4959-4804-8e06-0c412db92044.jpe

Create the vectors x and y with 1000 values.

Create a subplot with 2 panes:

  1. In the first pane, include a surface plot of f(x,y)
  2. In the second pane, include a mesh plot of f(x,y)

Include axis labels and titles for both plots.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

1.
% Matlab function file : TwoVarFunc.m
function [f_xy, f_xyMAX] = TwoVarFunc(xmin, xmax, ymin, ymax,N)
x = linspace(xmin,xmax,N);
y = linspace(ymin,ymax,N);
f_xy = (x'*y)./(sin(x)+cos(x));
f_xyMAX = max(max(f_xy));
end
%end of function

2.
% Matlab main script to use the function TwoVarFunc to get the value of the
% function and plot the surface and mesh plot
xmin = -4;
xmax = 4;
ymin = -7;
ymax = 7;
N = 1000;
x = linspace(xmin,xmax,N);
y = linspace(ymin,ymax,N);
[f_xy,f_xyMAX] = TwoVarFunc(xmin,xmax,ymin,ymax,N);
subplot(1,2,1);
surf(x,y,f_xy);
xlabel('X');
ylabel('Y');
zlabel('Z');
title('Surface plot of xy/(sin(x)+cos(x))')
subplot(1,2,2);
mesh(x,y,f_xy);
xlabel('X');
ylabel('Y');
zlabel('Z');
title('Mesh plot of xy/(sin(x)+cos(x))')
%end of script

Output:

Surface plot of xy/(sin(x)+cos(x)) Mesh plot of xy/(sin(x)+cos(x)) * 104 *104 2.5 2.5 2 1.5 1.5 0.5 0.5 Noy NO -0.5 -0.5 -1 -

Add a comment
Know the answer?
Add Answer to:
1) Create a matlab function that calculates: for Name your function TwoVarFunc : The inputs should...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a MATLAB function cobweb that plots a cobweb diagram to visualise the iterations per- forme...

    Write a MATLAB function cobweb that plots a cobweb diagram to visualise the iterations per- formed by an iterative method of the form xn+1 = g(xn). the cobweb function should take as its inputs a function handle g of a function that implements g, an initial estimate x0, the number of iterations to perform numits, values xmin, xmax, ymin and ymax, and a one dimensional array ud. The function g may be undefined or discontinuous at a finite number of...

  • Create a MATLAB function to perform Lagrange Interpolation. Your function will be used as illustrated below:...

    Create a MATLAB function to perform Lagrange Interpolation. Your function will be used as illustrated below: >> ya = Lagrange(x, y, a) where "x" is a vector of ? independent data values, "y" is a vector of ? dependent function values corresponding to "x", "a" is an arbitrary value of "x" for which you want to know the Westimate of "y", and "ya" is the estimate of the function at x=a. Print an error message and exit the function if...

  • MATLAB Problem Create a code to plot 2-D linear programming problems. label all constraints and hatch...

    MATLAB Problem Create a code to plot 2-D linear programming problems. label all constraints and hatch the infeasible region for constraints and bounds. Use arrow to show objective function gradient and linprog function. The user should input a cost function vector, two vectors xmax and xmin for bounds, and various constraints like: equality and inequality.

  • Please help me with this matlab problem, the answer should look like the picture below. Thank...

    Please help me with this matlab problem, the answer should look like the picture below. Thank you %1 Write an anonymous function that will receive data in the form of a plot function handle, x and y vectors, and a handle to a plot function and wil1 produce the plot. For example, a call to the function would look like the following: myPlot (@bar,x,y). x -pǐ : 0.25 : pi; y sin(x); % Piave you anonymous funcyion code here subplot...

  • Problem 1 MATLAB A Taylor series is a series expansion of a function f()about a given point a. For one-dimensional real...

    Problem 1 MATLAB A Taylor series is a series expansion of a function f()about a given point a. For one-dimensional real-valued functions, the general formula for a Taylor series is given as ia) (a) (z- a) (z- a)2 + £(a (r- a) + + -a + f(x)(a) (1) A special case of the Taylor series (known as the Maclaurin series) exists when a- 0. The Maclaurin series expansions for four commonly used functions in science and engineering are: sin(x) (-1)"...

  •    MATLAB SCRIPT PLEASE Matlab MATH 210 in 2020 Homework Assignment 8- Due 3/25, 11:59PM Each...

       MATLAB SCRIPT PLEASE Matlab MATH 210 in 2020 Homework Assignment 8- Due 3/25, 11:59PM Each plot should have its own figure associated with it. In all questions, give the figure a title, and label the acis. Save your matlab script as drill 10.m Do not use the fplot command. 1. Plot the function f(x) = (x + 5)2 for -5 <<<10. Include a plot title, and label both aris. 2. Use the subplot command to make two plots of...

  • MATLAB, please provide code script Objective: Create a function file that animates projectile motion defined by...

    MATLAB, please provide code script Objective: Create a function file that animates projectile motion defined by the following equations in a subplot. Your function should accept user inputs of launch speed and launch angle. The output of your function will be a top subplot that displays height (y) as a function of x. The bottom subplot should display the vertical velocity while the projectile is in motion. A video of what your animation should look like is posted with this...

  • MATLAB Any guidance is appreciated! Use meshgrid() function to create 2D grid coordinates with x- and...

    MATLAB Any guidance is appreciated! Use meshgrid() function to create 2D grid coordinates with x- and y- coordinates both from -12 to +12 in the increment 1/32. B) Calculate the function z shown below at every (x, y) point and store the result in a 2D array z Z = sin(squareroot x^2 + y^2)/ squareroot x^2 + y^2 c) Find the maximum value in array z and its corresponding index. The array may have more than one maximum points with...

  • MATLAB Problem HW7P2 (20 points) (5 pts) Write a user-defined MATLAB function called HW7P2_fn for the...

    MATLAB Problem HW7P2 (20 points) (5 pts) Write a user-defined MATLAB function called HW7P2_fn for the following math function 3 o-0.47x The input to the function is x and the output is y. Write the function such that x can be an array (use element-by-element operations) (15 pts) Use the function in (a) the command window to calculate y(-2) and y(5) (b) a script file HW7P2.m to determine y(x) for 0.001 Sx S 10 with 1000 points. Hint: Use the...

  • Creat a matlab function that calculates: f(x, y) = xy/(exp(x) + exp(-y)) for two vectors of...

    Creat a matlab function that calculates: f(x, y) = xy/(exp(x) + exp(-y)) for two vectors of values x and y. Name your function function_xy: The inputs should be in the same order: .X: vector of values • y: vector of values The ouput is: • A: is the calculated array f(x,y) Function 1 function (Outputs] = YourFunctionName(Inputs) 2 % Input code here end Code to call your function 1 X=-4:0.5:4 2 y=-5:1:5 4 A = function xy(x,y)

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT