Question

In: Mechanical Engineering

Plot the contour plot and the gradient (shown by arrows) for the function f(x, y) = -x2 + 2xy + 3y2

Plot the contour plot and the gradient (shown by arrows) for the function

f(x, y) = -x2 + 2xy + 3y2

Solutions

Expert Solution

Consider the function f(x, y) = -x2 + 2xy + 3y2

 

The objective is to draw the contour plot.

 

Firstly, generate a set of data for x and y range a using ‘meshgrid’ command.

 

Then based on these, calculate the data function and obtain differential x and y.

 

Using these differential values and ‘gradient’ command first order derivatives can be found.

 

The contour is plotted using ‘contour’ command for x, y and function values. Then for the contour and gradient, arrows are shown using ‘quiver’ command.

 

Mat-lab code for above problem is provided below.

Save this program as ‘Required problem’.

% Plot the contour plot and gradient (shown by arrows) for the function

clc; clear;

[x,y] = meshgrid(-2:0.25:2);

f=-x.^2+2*x.*y+3*y.^2;

dx = x(1,2) - x(1,1);

dy = y(2,1) - y(1,1);

[df_dx,df_dy] = gradient(f, dx, dy);

contour(x,y,f);

xlabel(\'x\');

ylabel(\'y\');

hold on;

quiver(x,y,df_dx,df_dy);

hold off;

The output of the code ‘Above problem’ in the figure window is shown below.


Related Solutions

Find the global maximum and global minimum of the function f(x, y) = y^2 − 2xy...
Find the global maximum and global minimum of the function f(x, y) = y^2 − 2xy + 4y on the square 1 ≤ x ≤ 3, 0 ≤ y ≤ 2.
Consider the vector field F(x, y) = <3 + 2xy, x2 − 3y 2> (b) Evaluate...
Consider the vector field F(x, y) = <3 + 2xy, x2 − 3y 2> (b) Evaluate integral (subscript c) F · dr, where C is the curve (e^t sin t, e^t cost) for 0 ≤ t ≤ π.
Find and classify all the extrema of the function f(x; y) = Exp(-x2 -y2 )*(x2 +...
Find and classify all the extrema of the function f(x; y) = Exp(-x2 -y2 )*(x2 + 2y2).
Consider the following function. g(x, y)  =  e2x2 + 3y2 + 12 y (a) Find the...
Consider the following function. g(x, y)  =  e2x2 + 3y2 + 12 y (a) Find the critical point of g. If the critical point is (a, b) then enter 'a,b' (without the quotes) into the answer box. (b) Using your critical point in (a), find the value of D(a, b) from the Second Partials test that is used to classify the critical point. (c) Use the Second Partials test to classify the critical point from (a).
Evaluate or solve the following A) dy/dx= -(2x2+y2)/(2xy+3y2) B)dy/dx=(1+y2)/(1+x2)xy C) (x2+1)dy/dx+2xy=4x2 given that when x=3,y=4 Already...
Evaluate or solve the following A) dy/dx= -(2x2+y2)/(2xy+3y2) B)dy/dx=(1+y2)/(1+x2)xy C) (x2+1)dy/dx+2xy=4x2 given that when x=3,y=4 Already rated.Best chegg expert
Curvilinear integral of the function f (x, y) = x2 + y2 on a (3,0) centered...
Curvilinear integral of the function f (x, y) = x2 + y2 on a (3,0) centered and 3 radius circle. a)Calculate the curvilinear integral by expressing the curve in parametrically. b)Calculate the curvilinear integral by expressing the curve in polar coordinates. c)Calculate the curvilinear integral by expressing the curve in cartesian coordinates.
Given the plot of y=f(x) below, find the plot of y=f−1(x). A coordinate plane has a...
Given the plot of y=f(x) below, find the plot of y=f−1(x). A coordinate plane has a horizontal x-axis labeled from negative 7 to 7 in increments of 1 and a vertical y-axis labeled from negative 7 to 7 in increments of 1. A curve starts at the point left-parenthesis negative 1 comma 0 right-parenthesis, rises at an increasing rate from left to right and passes through left-parenthesis 1 comma 1 right-parenthesis and left-parenthesis 4 comma 6 right-parenthesis. Select the correct...
bob's perferences over goods (x) and (y) are shown by U(x,y) = 2xy. his income is...
bob's perferences over goods (x) and (y) are shown by U(x,y) = 2xy. his income is 100. A) Calculate the optimal basket when Px = $50 and Py = $20. show your work B) Calculate his income and substituion effects ( if necessary, round two decimal places) if P falls to $40. show your work C) is good (x) normal or inferior? supprt/explain your answer D) Solve for the compensating variation. Explain what the value represents. show your work.
Let f(x, y) = xy3 − x 2 + 2y − 1. (a) Find the gradient...
Let f(x, y) = xy3 − x 2 + 2y − 1. (a) Find the gradient vector of f(x, y) at the point (2, 1). (b) Find the directional derivative of f(x, y) at the point (2, 1) in the direction of ~u = 1 √ 10 (3i + j). (c) Find the directional derivative of f(x, y) at point (2, 1) in the direction of ~v = 3i + 2j.
Consider F and C below. F(x, y, z) = 2xz + y2 i + 2xy j...
Consider F and C below. F(x, y, z) = 2xz + y2 i + 2xy j + x2 + 6z2 k C: x = t2,    y = t + 2,    z = 3t − 1,    0 ≤ t ≤ 1 (a) Find a function f such that F = ∇f. f(x, y, z) = x2z+xy2+2z3+c     (b) Use part (a) to evaluate    C ∇f · dr along the given curve C.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT