Please I need help with my Matlab homework Thanks Sometimes
Please I need help with my Matlab homework. Thanks
Sometimes in science functions depend on more than a single variable; as for example, for enzymes, the temperature and the concentration of the initial products control the activity. In these cases we need to go beyond the 2D Plots and use 3D Plots.
Define two functions of two variables as follows: y = x^2 – y^2 + x*y, and y = sin(x) * sin(y) and label them y1 and y2.
Create two intervals of values, one for x and one for y. For the first function, use an interval between -3 and 3 with step variation of 0.1 for both, x and y directions. For the second function, use the interval from 0 to 6 with an interval of variation of /20 for both directions.
Create a mesh and use the command surf to obtain the 3D Plot. Make sure to plot each function separately and forming a horizontal stack of plots. Hint: remember the command subplot.
Use the command contour, to plot the projection of the above obtained surfaces onto the xy-plane. Make sure to plot each contour separately.
Solution
Write the following code in the MATLAB SCRIPT EDITOR. Save it as a .m file and run it:
[X1,Y1]=meshgrid(-3:0.1:3,-3:0.1:3);
Z1=(X1.^2)-(Y1.^2)+X1.*Y1;
[X2,Y2]=meshgrid(0:pi/20:6*pi,0:pi/20:6*pi);
Z2=sin(X2).*sin (Y2);
figure
subplot(2,1,1);
surf(X1, Y1, Z1)
title(\'Function y1=x^2-y^2+x*y\')
subplot(2,1,2);
surf(X2, Y2, Z2)
title(\'Function y2=sin(x)*sin(y)\')
