Question

In: Computer Science

The following code must be written using matlab Create a contour plot of the following function...

The following code must be written using matlab

Create a contour plot of the following function f(x,y) = (x+y^2-10)^2 +(x^2+y^2+8) in range [-6,6] for both x and y

Clearly indicate in the plot the coordinates of the minimum ponts and the the corresponding function values in these points

Solutions

Expert Solution

ANSWER:

  • I have provided the properly commented code in both text and image format so you can easily copy the code as well as check for correct indentation.
  • I have provided the output image of the code so you can easily cross-check for the correct output of the code.
  • Have a nice and healthy day!!

CODE TEXT

% contour plot

% defining function f

f = @(x,y) (x + y.^2 - 10).^2 + (x.^2 + y.^2 + 8);

% defining x , y vector from -6 to 6

x = -6:0.2:6;

y = -6:0.2:6;

% generating meshgrid using x and y vector

[X,Y] = meshgrid(x,y);

Z = f(X,Y);

% ploting contour using contour function of matlab,

contour(X,Y,Z);

% labeling plot

xlabel("x value");

ylabel("y value");

title("Contour on function in xy range [-6,6]");

% holding plot to display min values

hold on;

% finding min value in Z, using min function

minZ = min(Z(:));

% finding locations for minZ in Z

[xMin,yMin] = find(Z==minZ);

% ploting points for minZ using plot3 function of matlab

plot3(X(xMin,yMin),Y(xMin,yMin),Z(xMin,yMin),"ro");

% displaying legend

legend("Z contour","Min Points");

CODE IMAGE

OUTPUT IMAGE


Related Solutions

This code is to be written in Matlab. Write a function that will plot cos(x) for...
This code is to be written in Matlab. Write a function that will plot cos(x) for x values ranging from -pi to pi in steps of 0.1, using black *'s. It will do this three times across in one Figure Window, with varying line widths. If no arguments are passed to the function, the line widths will be 1, 2, and 3. If on the other hand, an argument is passed to the function, it is multiplier for these values....
The following code must be written using matlab and must be using a for-loop. NOTE! Write...
The following code must be written using matlab and must be using a for-loop. NOTE! Write a computer program that assigns random integers for each entry and generates a row vector. Different random integers should be drawn from different intervals for position 1, position 2, position3 and position 4 of the array. After these first 4 positions are drawn. The whole thing should start over where position5 drawn from same interval as positions 1, position6 drawn from same interval as...
The following code must be written using matlab and must be using a for-loop. NOTE! Write...
The following code must be written using matlab and must be using a for-loop. NOTE! Write a computer program that assigns random integers for each entry and generates a row vector. Different random integers should be drawn from different intervals in chunks of 4 , that is chunk1-chunk2-chunk3-chunk4 The parameters for specifying the lintervals by which the random numbers should be drawn should be able to change and be hardcoded in the script, however, be hardcoded in the script.
The following code must be written using matlab How to loop through a vector in matlab...
The following code must be written using matlab How to loop through a vector in matlab and assigning a value to every 4th entry. The vector could be of any length. Thanks
The following code must be written using matlab How to get the elements that are different...
The following code must be written using matlab How to get the elements that are different in two set without using the setdiff function in matlbab?
The following code must be written in Matlab I want to print the following in Matlab...
The following code must be written in Matlab I want to print the following in Matlab (x1,x2, x3) = (0.33333, 0.33333, 0.33333)  . The whole thing should be on the same line. I need to use fprintf and write out the coordinates with 5 decimal places of variable x = (0.33333, 0.33333, 0.33333) Thanks!
Plot the original data and the regression “line” ************USING Matlab************. "Submit plot" USING MATLAB! USING MATLAB!...
Plot the original data and the regression “line” ************USING Matlab************. "Submit plot" USING MATLAB! USING MATLAB! USING MATLAB! ONLY BY USING MATLAB!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 14.9 The concentration of E. coli bacteria in a swimming area is monitored after a storm: t (hr)                     4           8         12        16    20 24 c (CFU/100 mL) 1600     1320   1000     890 650 560 The time is measured in hours following the end of the storm and the unit CFU is a .colony forming unit.. Use this data to estimate (a)...
Give me a MATLAB code which integrates any function using Romberg integration The code must work...
Give me a MATLAB code which integrates any function using Romberg integration The code must work fine or else I will down vote the answer badly Dont post if you dont know
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 functionf(x, y) = -x2 + 2xy + 3y2
I was asked to create a function called mydrawing in Matlab to draw or plot lines...
I was asked to create a function called mydrawing in Matlab to draw or plot lines onto a graph, using a so called pen. The pen will start at the origin and will move along the +ve horizontal axis. The pen is also supplied with a list of commands in a form of a string, to draw or plot the lines onto the graph. The string commands are: 1) 'F' : the pen moves forward by x = 1.0 2)...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT