Please help me with these plots!! Write a Matlab program that asks the user to e
ID: 1811536 • Letter: P
Question
Please help me with these plots!!
Write a Matlab program that asks the user to enter a positive number a between 2 and 10. Then create x and y vectors from -a to +a with spacing 0.05. Use the meshgrid function to map x and y onto two new two-dimensional arrays called X and Y. Use your new arrays to calculate the vector Z, with magnitude Z = X2 + Y2 exp (-X2 -Y2) Using the subplot function, generate the following 3D plots on one page: Use the plot3 function to create a three-dimensional plot of Z. Use the mesh function to create a three-dimensional plot of Z. Use the surf function to create a three-dimensional plot of Z. Use the contour function to create a three-dimensional plot of Z. Don't forget to label your axes and title your plots appropriately.Explanation / Answer
aTEMP = input('Please input a number between 2 and 10 ', 's'); %User GIves Input In String
a = str2double(aTEMP); %String Converted to Double Integer
x = -a:0.05:a;
y = x;
[X,Y] = meshgrid(x,y);
Z = (sqrt(X^2 + Y^2))*exp(-(X^2 + Y^2));
subplot(2,2,1)
plot3(X,Y,Z); %Part (a)
xlabel('X');
ylabel('Y');
zlabel('Z');
grid on
subplot(2,2,2)
mesh(X,Y,abs(Z)); %Part (b)
xlabel('X');
ylabel('Y');
zlabel('Z');
grid on
subplot(2,2,3)
surf(X,Y,abs(Z)); %Part (c)
xlabel('X');
ylabel('Y');
zlabel('Z');
grid on
subplot(2,2,4)
contour(X,Y,Z); %Part (d)
xlabel('X');
ylabel('Y');
zlabel('Z');
grid on
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.