In: Computer Science
MATLAB
Option 1:Z=sinX+sinY
Option 2:Z=sinX+cosY
Option 3:Z=cosX+cosY
and the bottom 3D surface plot should use one of the equations
Option 1:Z=sinX - sinY
Option 2:Z=sinX - cosY
Option 3:Z=cosX - cosY
For both plots, use a mesh grid with the same range for both the x-axis and y-axis. Use a range of -2π to 2π; the step (increment) of both dimensions of the grid should be 0.25.
Use a menu or listdlg command to allow the user to select which functions to use. Be sure to output which option the user selected. And, use an if statement that, based on the option chosen, creates plots with the correct functions.
Run your program twice with different user input and provide the output for each run.
top = menu('Select top plot
equation',{'1:Z=sinX+sinY','2:Z=sinX+cosY','3:Z=cosX+cosY'});
bottom = menu('Select bottom plot
equation',{'1:Z=sinX-sinY','2:Z=sinX-cosY','3:Z=cosX-cosY'});
x=-2*pi:.25*2*pi;
y=x;
[X,Y]=meshgrid(x,y);
subplot(2,1,1)
if top==1
fprintf('For top plot you selected sin(x)+sin(y)\n')
Z=sin(X)+sin(Y);
elseif top==2
fprintf('For top plot you selected sin(x)+cos(y)\n')
Z=sin(X)+cos(Y);
else
fprintf('For top plot you selected cos(x)+cos(y)\n')
Z=cos(X)+cos(Y);
end
surf(X,Y,Z)
subplot(2,1,2)
if bottom==1
fprintf('For bottom plot you selected sin(x)-sin(y)\n')
Z=sin(X)-sin(Y);
elseif bottom==2
fprintf('For bottom plot you selected sin(x)-cos(y)\n')
Z=sin(X)-cos(Y);
else
fprintf('For bottom plot you selected cos(x)-cos(y)\n')
Z=cos(X)-cos(Y);
end
surf(X,Y,Z)