KeytoMatlabExercise8SchoolofMathematicalSciencesXiamenUniversityhttp:/gdjpkc.xmu.edr Key to MATLAB Exercise 8-Graphics-Curve > clear; xlinspace(0, 6): y=exp(-03 *x). cos(2. x) > clear; tlinspace(0, 2 pi); x=4, sin(t); y=4. cos(t) > plot(x,y) 回区 Figure1 包回区 口日回长日国“日日回长日国 >> clear; ezplot(x^4+y4-8*x^2-10*y^2+16) > clear; theta=-2 pi: 0. 1: 2 pi; rho=4*cos(2 theta > polar(theta, rho) -Figure I 回区 Figure 1 包回区 Eile Edit yiew Insert Tools Desktop Window Help x Eile Edit yiew Insert Tools Desktop lindow Help +y48x210y2+16=0 > clear; x=linspace(0, 10) >>y1=x/(1+x);y2=5*y1;y3=10°y1 > plot(x, yl, x, y2, I, x, y3, 'g) Key to Ex8-I
Key to MATLAB Exercise 8 School of Mathematical Sciences Xiamen University http://gdjpkc.xmu.edu.cn Key to Ex81 Key to MATLAB Exercise 8 – Graphics Curve 1. 1) >> clear; x=linspace(0,6); y=exp(0.3.*x).*cos(2.*x); >> plot(x,y) 2) >> clear; t=linspace(0,2*pi); x=4.*sin(t); y=4.*cos(t); >> plot(x,y) 3) >> clear; ezplot('x^4+y^48*x^210*y^2+16') 4) >> clear; theta=2*pi:0.1:2*pi; rho=4*cos(2*theta); >> polar(theta,rho) 2. >> clear; x=linspace(0,10); >> y1=x./(1+x); y2=5*y1; y3=10*y1; >> plot(x,y1,x,y2,'r',x,y3,'g')
KeytoMatlabExercise8SchoolofMathematicalSciencesXiamenUniversityhttpgdjpkc.xmu.edu.cr >> legend'yl’y2y3) > grid on >> xlabel(X-轴); ylabel(函数值) Eile Edit Yiew Insert Tools desktop Window Help D日舀(回装日国回 > title(' Plot of \rho=4cos theta File Edit Yiew Insert Tools Desktop Window Help D一日舀Q回*日囝 Plot of p=4cos30 >> clear > figure(1) >> ezplot(x24+y4-2*(x^2+y^2)-10) > figure(2) >> explo(x^4+y24-2*(x^2+y^2)-(-0.7) > figure(3) >> ezplot(x^4+y4-2*(x^2+y^2)-(-10) > figure(4) >> ezplot(x^4+y4-2*(x^2+y^2)-(-105) >> subplot(2,2,1), ezplot(x^4+y24-2*(x^2+y^2)-1 >> subplot(22,2) ezplot(x^4+y^4-2*(x^2+y2)(-0.7)y >> subplot(22,3); ezplot(x24+y4-2*(x^2+y^2)(-1.0) ey to Ex8-2
Key to MATLAB Exercise 8 School of Mathematical Sciences Xiamen University http://gdjpkc.xmu.edu.cn Key to Ex82 >> legend('y1','y2','y3') >> grid on >> xlabel('X轴'); ylabel('函数值') 3. >> title('Plot of \rho=4cos3\theta') 4. 1) >> clear; >> figure(1) >> ezplot('x^4+y^42*(x^2+y^2)1.0'); >> figure(2) >> ezplot('x^4+y^42*(x^2+y^2)(0.7)'); >> figure(3) >> ezplot(' x^4+y^42*(x^2+y^2)(1.0)'); >> figure(4) >> ezplot(' x^4+y^42*(x^2+y^2)(1.05)'); 2) >> subplot(2,2,1); ezplot('x^4+y^42*(x^2+y^2)1.0') >> subplot(2,2,2); ezplot('x^4+y^42*(x^2+y^2)(0.7)') >> subplot(2,2,3); ezplot('x^4+y^42*(x^2+y^2)(1.0)')
Key to MATLAB Exercise 8 School of Mathematical Sciences Xiamen Univer http:/edjpkc.xmu.ed >> subplot(22,4); ezplot(x24+y4-2*(x^2+y^2)(-1.05) Eile edit yiew Insert Tool: Desktop Window Help D日各心《Q回桌日图■回 x+y42x22y21/0=0x4+y4-2x22y2+7/0=0 x4+y2x22y2+1=0x4+y42x22y2+2120=0 >> figure(1) tlinspace(0.6);x=0.5^2,y=0.14tA3;z=9°c0(2+1) > plot(x,y, z,'m") > figure(2); subplot, t=linspace(0, 9): x=0.5*sin(t); y=0. 1*cos(t): z=9*cos(2*t) > plot(x, y, z,'m") 包回 回囟 Eile Edit yiew Insert Tools Desktop Lindow Help Eile Edit Yiew Insert Tools Desktop Window Help x 口日舀Q州回果国 回舀國回果日图 0 6 >> figure;,x=0,1,45,7;y=[13,4,5,56;plot(xy-m+) > hold on, xl=[1, 2, 3, 4, 5]:y1=[2, 4, 3, 6, 4; plot(xl, yl, cs); legend(' Group 1,"Group 2); Key to Ex8-3
Key to MATLAB Exercise 8 School of Mathematical Sciences Xiamen University http://gdjpkc.xmu.edu.cn Key to Ex83 >> subplot(2,2,4); ezplot('x^4+y^42*(x^2+y^2)(1.05)') 5. >> figure(1); t=linspace(0,6); x=0.5*t.^2; y=0.1*t.^3; z=9*cos(2*t); >> plot3(x,y,z,'m*') >> figure(2); subplot; t=linspace(0,9); x=0.5*sin(t); y=0.1*cos(t); z=9*cos(2*t); >> plot3(x,y,z,'m*') 6. >> figure; x=[0,1,4,5,7]; y=[1,3,4,5, 5.6]; plot(x,y,'m*'); >> hold on; x1=[1,2,3,4,5];y1=[2,4,3,6,4]; plot(x1,y1,':cs'); legend('Group 1', 'Group 2');
KeytoMatlabExercise8SchoolofMathematicalSciencesXiamenUniversityhttpgdjpkc.xmu.edu.cr d Figure 1 包区 Eile Edit yiew Insert Tools Desktop Lindow Helpy D回舀Q州回口图■” >>f1/(5+4 cos(x)), ezplot(f) - Figure 1 Eile Edit View Insert Iools Desktop Lindow Help 3 D—回舀心Q回←日图 15+4cos(x) > fl=diff(f); ezplot(fl) Eile Edit yiew Insert Tools Desktop lindow Help y D舀心Q回←国 4/65+4c05(x)2sin(x) > f2=diff(f, 2): ezplot( f2)
Key to MATLAB Exercise 8 School of Mathematical Sciences Xiamen University http://gdjpkc.xmu.edu.cn Key to Ex84 7. >> f='1/(5+4*cos(x))';ezplot(f) >> f1=diff(f);ezplot(f1) >> f2=diff(f,2);ezplot(f2)
KeytoMatlabExercise8SchoolofMathematicalSciencesXiamenUniversityhttpgdjpkc.xmu.edu.cr File Edit yiew Insert Tools Desktop Mindow Help D—圖舀心Q回长日图 2/5+4c0s(x)3si(y2+415+4c05(x)2cos(x) D哆舀伐Q回桌口国 (an(12x)2 At first glance, the plots for f and g look the same. Look carefully, however, at their formulas and their ranges on the y-axis > subplot( 1, 2, 1): ezplot(f) File Edit View Insert Tools Desktop Window Help 3 D≥回舀Q滑回长日图 x)2+9) 0 f and g. It has a complicated formula, but its graph looks li
Key to MATLAB Exercise 8 School of Mathematical Sciences Xiamen University http://gdjpkc.xmu.edu.cn Key to Ex85 >> g= int(int(f2)); ezplot(g); At first glance, the plots for f and g look the same. Look carefully, however, at their formulas and their ranges on the yaxis. >> subplot(1,2,1); ezplot(f) >> subplot(1,2,2); ezplot(g) e is the difference between f and g. It has a complicated formula, but its graph looks like a
KeytoMatlabExercise8SchoolofMathematicalSciencesXiamenUniversityhttpgdjpkc.xmu.edu.cr constant >>e=f-g > subplot(1, 1, 1): ezplot(e) e 1/(5+4*cos(x))+8tan(1/2*xy^2+9) A Figure 1 Eile Edit yiew Insert Tools Desktop Lindow Help x 1/5+4c0s(x)1(a12x)2+9) To show that the difference really is a constant, simplify the equation. This comfirms that the ference between them really is a constant ezplot(e) 8. We finish the exercise by following 4 different functions (1) ezplot function >> ezploto(x^2+y^2-1") >> axis square >>hold on >> explo(x^2+y^2-4) >> explo(x^2+y^2-16) t让14t工sert 里ade1p 口≥日醪代回长日国日回 Key to Ex8-6
Key to MATLAB Exercise 8 School of Mathematical Sciences Xiamen University http://gdjpkc.xmu.edu.cn Key to Ex86 constant. >> e=fg >> subplot(1,1,1); ezplot(e) e = 1/(5+4*cos(x))+8/(tan(1/2*x)^2+9) To show that the difference really is a constant, simplify the equation. This comfirms that the difference between them really is a constant. >> e=simple(e) ezplot(e) e = 1 8. We finish the exercise by following 4 different functions. (1)ezplot function >> ezplot('x^2+y^21') >> axis square >> hold on >> ezplot('x^2+y^24') >> ezplot('x^2+y^216')
KeytomatlabExercise8SchoolofMathematicalsCiencesXiamenUniversityhttp:/gdjpkc.xmu.edu.ci (2)plot functi >>tlinspace(0, 2*pi): xl=sin(t): yl=cos(t); plot(xl, y1) >> axis square >>hold on >>x2=2.sin(t): y2=2. cos(t); plot(x2, y2) >>X3=4. *sin(t); y3=4. *cos(t); plot(x3, y3) (3)polar function > theta=0: 0. 1: 2 pi; rI=ones(l, numel(theta); polar( theta, r 1) hold on >> r2=2 ones(l, numel(theta), polar(theta, r 2) (4)line function >> theta=0:0.12*pi+0.1 >>line(cos(theta), sin( theta)) > axis equal > hold on >> line(2cos(theta), 2*sin( theta)) >>line(4*cos(theta), 4*sin( theta)) 9. > phi=[pi/2: 4 pi/5: 4pi, pi/2 B=exp(i*phi); xI=real(B):yl=imag(B) >> plot(x1,y1r; axis square;,tle五角星) Insert D日舀心回要日图 五角星 -05
Key to MATLAB Exercise 8 School of Mathematical Sciences Xiamen University http://gdjpkc.xmu.edu.cn Key to Ex87 (2) plot function >> t=linspace(0,2*pi); x1=sin(t); y1=cos(t); plot(x1,y1) >> axis square >> hold on >> x2=2.*sin(t); y2=2.*cos(t); plot(x2,y2) >> x3=4.*sin(t); y3=4.*cos(t); plot(x3,y3) (3) polar function >> theta=0:0.1:2*pi; r1=ones(1,numel(theta)); polar(theta,r1) >> hold on >> r2=2*ones(1,numel(theta)); polar(theta,r2) >> r3=4*ones(1,numel(theta)); polar(theta,r3) (4) line function >> theta=0:0.1:2*pi+0.1; >> line(cos(theta),sin(theta)); >> axis equal >> hold on >> line(2*cos(theta),2*sin(theta)); >> line(4*cos(theta),4*sin(theta)); 9. >> phi=[pi/2:4*pi/5:4*pi, pi/2]; B=exp(i*phi); x1=real(B);y1=imag(B); >> plot(x1,y1,'r'); axis square; title('五角星')