Key to MATLAB Exercise 9 SchoolofMathematicalSciencesXiamenUniversityhttp://gdjpkc.xmu.edu.cn Key to MATLAB Exercise 9-Graphics-Surface >>clear; clf, xlinspace(-4, 4, 20): y=linspace(-5, 5, 20); >>(X,Y]= meshgrid(x,y);Z=0.3°eXp(-0.15°(X^2+¥^2)-0.3*eXp(0.15°(X.^2+Y.A2) > plot(X,Y, 2); grid on > mesh(X,Y,Z) B如气:日 >>surf(X,Y,z) Key to Ex9-1
Key to MATLAB Exercise 9 School of Mathematical Sciences Xiamen University http://gdjpkc.xmu.edu.cn Key to Ex91 Key to MATLAB Exercise 9 – Graphics Surface 1. >> clear; clf; x=linspace(4,4,20); y=linspace(5,5,20); >> [X, Y]=meshgrid(x,y); Z=[0.3*exp(0.15*(X.^2+Y.^2)) 0.3*exp(0.15*(X.^2+Y.^2))]; 1) >> plot3(X,Y,Z); grid on; 2) >> mesh(X,Y,Z) 3) >> surf(X,Y,Z)
Key to MATLAB Exercise 9 SchoolofMathematicalSciencesXiamenUniversityhttp://gdjpkc.xmu.edu.cn > mesh(X,Y, z) it- yis Atrt Taal: Detha yidan. yA > surfc(, Y, z) B点口一 >>x=(9: 9;y=[-9: 9]:(X,Y=meshgrid(x, y) >> XY=(X. 2+Y.2).(1/2)+eps; Z=sin(XY) / XY > subplot(1, 3, 1): plot(x,Y,z) > title('Display by plots function ); xlabel('x): ylabel('y); zlabel(z); grid on > subplot( 1, 3, 2); mesh(X,Y, z); > title('Display by mesh function ); xlabel('x): ylabel('y); zlabel('z'); grid on > subplot(1, 3, 3); surf(X,Y, Z > title('Display by surf function); xlabel('x); ylabel(y); zlabel('z); grid on
Key to MATLAB Exercise 9 School of Mathematical Sciences Xiamen University http://gdjpkc.xmu.edu.cn Key to Ex92 4) >> meshz(X,Y,Z) 5) >> surfc(X,Y,Z) 2. >> clear; clf; >> x=[9:9];y=[9:9]; [X,Y]=meshgrid(x,y); >> XY= (X.^2+Y.^2).^(1/2)+eps; Z=sin(XY)./XY; 1) >> subplot(1,3,1); plot3(X, Y, Z); >> title('Display by plots function'); xlabel('x'); ylabel('y'); zlabel('z'); grid on 2) >> subplot(1,3,2); mesh(X,Y,Z); >> title('Display by mesh function'); xlabel('x'); ylabel('y'); zlabel('z'); grid on 3) >> subplot(1,3,3); surf(X, Y, Z); >> title('Display by surf function'); xlabel('x'); ylabel('y'); zlabel('z'); grid on
Key to MATLAB Exercise 9 School of Mathematical Sciences Xiamen University htt kc xmu edu. cn - Figure I Eile Edit Yiew Insert Tools Desktop lindow Help 日Q回果日国日 Display by plots function Display by mesh function Display by surf function 0 y-10-10 > clear: clf >>UF[0: 0.5: 4*pi]: v=[0: 0.5: 4 pi: [U, V=meshgrid(u, v) >>X=U'cos(V): Y=U*sin(V): Z=2*U+8*V > figure(1); plot(X, Y, Z); grid on > figure(2); mesh(X, Y, 2); grid on 母回日日日口
Key to MATLAB Exercise 9 School of Mathematical Sciences Xiamen University http://gdjpkc.xmu.edu.cn Key to Ex93 3. >> clear; clf; >> u=[0:0.5:4*pi]; v=[0:0.5:4*pi]; [U,V]=meshgrid(u,v); >> X=U.*cos(V); Y=U.*sin(V); Z=2*U+8*V; 1) >> figure(1); plot3(X,Y,Z); grid on 2) >> figure(2); mesh(X,Y,Z); grid on
Key to MATLAB Exercise 9 SchoolofMathematicalSciencesXiamenUniversityhttp://gdjpkc.xmu.edu.cn 3) > figure(3); surf(X,Y, 2); grid on >> clear close all >> tlinspacet(0,6),x=0.52;y=0.14^3;z=9(c08(2*t) > plot(x,y, z); grid or B点口 > theta=linspace(-pi/2, 0); leq= linspace(-pi, pi) > TTHETA, LEQImeshgrid( theta, leg) >>X=COS(THETA).sin(LEQ): Y=cos(THETA). "cos(LEQ): Z=sin(THETA) >> mesh(X, Y, Z); axis equal Key to Ex9-4
Key to MATLAB Exercise 9 School of Mathematical Sciences Xiamen University http://gdjpkc.xmu.edu.cn Key to Ex94 3) >> figure(3); surf(X,Y,Z); grid on 4. >> clear; close all; >> t=linspace(0,6); x=0.5*t.^2; y=0.1*t.^3; z=9*( cos(2*t)); >> plot3(x,y,z); grid on 5. >> theta=linspace(pi/2,0); leq=linspace(pi,pi); >> [THETA,LEQ]=meshgrid(theta,leq); >> X=cos(THETA).*sin(LEQ);Y=cos(THETA).*cos(LEQ); Z=sin(THETA); >> mesh(X,Y,Z); axis equal;
Key to MATLAB Exercise 9 SchoolofMathematicalSciencesXiamenUniversityhttp://gdjpkc.xmu.edu.cn >> t=pi/16: pi/8: 2* pl; x=cos(t): y=sin(t) >> fill(x,y;b), axis square;tite正十六边形) Eil. Eit yie Last tault Desktop Yiadww wall ≥日A我回日目口口 > phi=pi/2: 4 pi/5: 4 pi; B=exp(i phi): xl=real(B); yl=imag(B) ttle五角星) 國: and(10,1)*10;V=rand(10,1)*10
Key to MATLAB Exercise 9 School of Mathematical Sciences Xiamen University http://gdjpkc.xmu.edu.cn Key to Ex95 6. >> t=pi/16: pi/8:2*pi; x=cos(t);y=sin(t); >> fill(x,y,'b'); axis square; title('正十六边形') 7. >> phi=pi/2:4*pi/5:4*pi; B=exp(i*phi); x1=real(B); y1=imag(B); >> fill(x1,y1,'r'),axis square; title('五角星') 8. >> u=rand(10,1)*10; v=rand(10,1)*10;
Key to MATLAB Exercise 9 SchoolofMathematicalSciencesXiamenUniversityhttp://gdjpkc.xmu.edu.cn >>xu. cos(v); y=u. sin(v): Z=2 u+2V >>xlin=linspace(min(x), max(x), 33) > yin= linspace(min(y), max(y), 33) shgrid(xlin, lin) >>Z=griddata(x,y, z, X,Y,cubic) >>mesh(X,Y, z) > axis tight; hold on plot(x, y, z, ., MarkerSize, 15) Key to Ex9-6
Key to MATLAB Exercise 9 School of Mathematical Sciences Xiamen University http://gdjpkc.xmu.edu.cn Key to Ex96 >> x=u.*cos(v); y=u.*sin(v); z=2*u+2*v; >> xlin = linspace(min(x),max(x),33); >> ylin = linspace(min(y),max(y),33); >> [X,Y] = meshgrid(xlin,ylin); >> Z = griddata(x,y,z,X,Y,'cubic'); >> mesh(X,Y,Z) >> axis tight; hold on >> plot3(x,y,z,'.','MarkerSize',15)