Читать книгу Applied Numerical Methods Using MATLAB - Won Y. Yang - Страница 19
1.1.5 Three Dimensional (3D) Graphic Output
ОглавлениеMATLAB has several three‐dimensional (3D) graphic plotting commands such as ‘ plot3()
’, ‘ mesh()
’, and ‘ contour()
’. ‘ plot3()
’ plots a two‐dimensional (2D) valued‐function of a scalar‐valued variable; ‘ mesh()
’/‘ contour()
’ plots a scalar valued‐function of a 2D variable in a mesh/contour‐like style, respectively.
Readers are recommended to use the ‘ help
’ command for detailed usage of each command. Try running the above MATLAB script “nm01f04.m” to see what figures will appear (Figure 1.4).
%nm01f04.m: to plot 3D graphs t=0:pi/50:6*pi; expt= exp(-0.1*t); xt= expt.*cos(t); yt= expt.*sin(t); % dividing the screen into 2x2 sections clf subplot(521), plot3(xt,yt,t), grid on %helix subplot(522), plot3(xt,yt,t), grid on, view([0 0 1]) subplot(523), plot3(t,xt,yt), grid on, view([1 -3 1]) subplot(524), plot3(t,yt,xt), grid on, view([0 -3 0]) x=-2:.1:2; y=-2:.1:2; [X,Y] = meshgrid(x,y); Z =X.̂2 + Y.̂2; subplot(525), mesh(X,Y,Z), grid on %[azimuth,elevation]=[-37.5,30] subplot(526), mesh(X,Y,Z), view([0,20]), grid on pause, view([30,30]) subplot(527), contour(X,Y,Z) subplot(528), contour(X,Y,Z,[.5,2,4.5])
Figure 1.4 3D graphs drawn by using plot3()
, mesh()
, and contour()
.