MATLAB程序設(shè)計(jì)教程第二版課后詳解_第1頁(yè)
MATLAB程序設(shè)計(jì)教程第二版課后詳解_第2頁(yè)
MATLAB程序設(shè)計(jì)教程第二版課后詳解_第3頁(yè)
已閱讀5頁(yè),還剩26頁(yè)未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、un it3-8MATLAB第二版課后答案unit3實(shí)驗(yàn)指導(dǎo)1、n=i nput(' 請(qǐng)輸入一個(gè)三位數(shù):');a=fix( n/100);b=fix( n-a*100)/10);c=n-a*100-b*10;d=c*100+b*10+a2( 1)n=input('請(qǐng)輸入成績(jī)');switch ncase num2cell(90:100)p='A'case num2cell(80:89)p='B'case num2cell(70:79)p=C;case num2cell(60:69)p='D'otherwisep=&

2、#39;E'endprice=p(2) n=input('請(qǐng)輸入成績(jī)');if n>=90&n <=100p='A:elseif n>=80&n <=89p='B:elseif n>=70&n <=79p=C;elseif n>=60&n <=69p='D'elsep='E'endprice=p(3 ) tryn;catchprice='erroe'end3n=1,5,56,4,3,476,45,6,3,76,45,6,4,3,

3、6,4,23,76,908,6;a=n ;b=n ;for m=2:20if n(m )>aa=n( m);elseif n(m )<bb=n( m);endendmax=amin=b法2n=1,5,56,4,3,476,45,6,3,76,45,6,4,3,6,4,23,76,908,6;mi n=mi n(n)max=max (n)4b=-3.0:0.1:3.0;for n=1:61a=b( n);y(n )=(exp(0.3*a)-exp(-0.3*a)/2*si n(a+0.3)+log(0.3+a)/2);endy5y1=0;y2=1;n=input('請(qǐng)輸入n的

4、值:');for i=1: ny仁y1+1/iA2;y2=y2*(4*i*i)/(2*i-1)*(2*i+1);endyiy26A=1,1,1,1,1,1;2,2,2,2,2,2;3,3,3,3,3,3;4,4,4,4,4,4;5,5,5,5,5,5;6,6,6,6,6,6;n=input('請(qǐng)輸入n的值:');if n<=5&n>=0disp(A( nelseif n<0disp(lasterr);else disp(A(6,:);disp(lasterr);end7 (1 )f=;for n=1:40f(n )=n+10*log( n2+5

5、);endy=f(40)/(f(30)+f(20)(2)f=;a=0;for n=1:40f(n )=a+n*( n+1);a=f(n);endy=f(40)/(f(30)+f(20)8y=0;m=input('輸入 m 的值:');n=input('輸入 n 值:');for i=1: ny=y+iAm;endy*function s=shi8_1( n,m)s=0;for i=1: ns=s+iAm;end*shi8_1(100,1)+shi8_1(50,2)+shi8_1(10,1/2)思考練習(xí)2N=1,2,3,4,5;2.*NN./21./N1./N.A

6、23s=fix(100*ra nd(1,20)*9/10+10)y=sum(s)/20j=0;for i=1:20if s(i)< y&rem(s(i),2)=0j=j+1;A(j)=s(i);else con ti nue;endendA4y1=0;y2=0;n=input('請(qǐng)輸入n的值:');for i=1: ny1= y1+-(-1)Ai/(2*i-1);y2=y2+1/4Ai;endyiy2unit4實(shí)驗(yàn)指導(dǎo)1 (1)x=-10:0.05:10;y=x-x.A3./6;Plot(x,y)(2)x=-10:0.5:10;ezplot('xA2+2*

7、yA2-64',-8,8);grid on;t=-pi:pi/10:pi;y=1./(1+exp(-t); subplot(2,2,1);bar(t,y); title('條形圖(t,y)');axis(-pi,pi,0,1);subplot(2,2,2);stairs(t,y,'b');title('階梯圖(t,y)'); axis(-pi,pi,0,1);subplot(2,2,3); stem(t,y,'k');title('桿圖(t,y)'); axis(-pi,pi,0,1);subplot(2,

8、2,4); loglog(t,y,'y');title('對(duì)數(shù)坐標(biāo)圖(t,y)');3 (1)t=0:pi/50:2*pi;r=5.*cos(t)+4; polar(t,r);title('rho=5*costheta+4');t=-pi/3:pi/50:pi/3;r=5.*(s in (t).A2)./cos(t); polar(t,r);4 (1)t=0:pi/50:2*pi;x=exp(-t./20).*cos(t);y=exp(-t./20).*si n( t);z=t;plot3(x,y,z);grid on;(2)x,y=meshgr

9、id(-5:5); z=zeros(11)+5; mesh(x,y,z);shad ing in terp;5x,y,z=sphere(20); surf(x,y,z);axis off;shad ing in terp;m=moviei n(20);for i=1:20axis(-i,i,-i,i,-i,i) m(:,i)=getframe;endmovie(m,4);思考練習(xí)2 (1)x=-5:0.1:5;y=(1./(2*pi).*exp(-(x.A2)/2); plot(x,y);(2)t=-2*pi:0.1:2*pi;x=t.*s in( t);y=t.*cos(t);plot(x,

10、y);grid on;3t=O:pi/1OOO:pi;x=si n(3.*t).*cos(t);y1=si n(3.*t).*si n( t);y2=2.*x-0.5;plot(x,y1,'k',x,y2);hold on;k=fi nd(abs(y1-y2)<1e-2);x1=x(k);y3=2.*x1-0.5;plot(x1,y3,'rp');4x=-2:0.01:2;y=s in (1./x);subplot(2,1,1);plot(x,y);subplot(2,1,2);fplot('si n(1./x)',-2,2,1e-4);5

11、 (1)i=-4*pi:0.1:10;j=12./sqrt(i);polar(i,j);title('rho=12/sqrt(theta)')(2)a=-pi/6:0.01:pi/6;b=3.*asi n( a).*cos(a)./(si n(a).A3+(cos(a)43);polar(a,b);6 (1)u,v=meshgrid(-4:0.1:4);x=3.*u.*s in (v);y=2.*u.*cos(v);z=4.*u.A2;subplot(2,1,1); mesh(x,y,z);subplot(2,1,2); surf(x,y,z);(2)x,y=meshgrid(

12、-3:0.2:3); z=-5./(1+x.A2+y.A2); subplot(1,2,1);mesh(x,y,z); subplot(1,2,2);surf(x,y,z);unit5實(shí)驗(yàn)指導(dǎo)1A=ra ndn (10,5)x=mea n(A)y=std(A)Max=max(max(A)Min=min( mi n( A)Sumha ng=sum(A,2)SumA=sum(Sumha ng)B=sort(A);C=sort(B,2,'desce nd');C2 (1)a=0:15:90;b=a./180.*pi;s=s in(b)c=0:15:75;d=c./180.*pi;t=

13、ta n(d)e=i nput('請(qǐng)輸入想計(jì)算的值:');S=si n(e/180*pi)T=ta n( e/180*pi)S仁in terp1(a,s,e,'spli ne')T1=i nterp1(c,t,e,'spli ne')P1=polyfit(a,s,5);P2=polyfit(c,t,5);S2=polyval(P1,e)T2=polyval(P2,e)(2)n=1,9,16,25,36,49,64,81,100;N=sqrt (n);x=in put('ji sua n zhi :');in terp1( n, N

14、,x,'cubic')3N=64;T=5;t=li nspace(O,T,N);h=exp(-t);dt=t (2)-t(1);f=1/dt;X=fft(t);F=X(1:N/2+1);f=f*(0:N/2)/N;plot(f,abs(F),'-*')4P=2,-3,0,5,13;Q=1,5,8;p=polyder(P)q=polyder(P ,Q)a,b=polyder(P ,Q)5P1=1,2,4,0,5;P2=0,1,2;P3=1,2,3;P=P1+co nv(P2,P3)X=roots(P)A=-1,1.2,-1.4;0.75,2,3.5;0,5,2.5

15、;p=polyval(P ,A)思考練習(xí)4A=ra nd(1,30000);a=mea n(A)b=std(A)Max=max(A)Min=mi n(A)n=0;for i=1:30000if(A(i)>0.5)n=n+1;endendny=n/300005p=45,74,54,55,14;78,98,45,74,12;87,98,85,52,65M,S=max(p)N,H=mi n(p)jun zhi=mea n( p,1)fan gcha=std(p,1,1)zon g=sum(p,2);Max,wei=max(z ong)Mi n, wei=mi n(zong)zcj,xsxh=s

16、ort(z on g,'desce nd')6x=1:10:101;y=0,1.0414,1.3222,1.4914,1.6128,1.7076,1.7853,1.8513,1.9085,1.9590,2.0043;p,s=polyfit(x,y,5)a=1:5:101;y1=polyval(p,a);plot(x,y,':o',a,y1,'-*')unit6實(shí)驗(yàn)指導(dǎo)1A=1/2,1/3,1/4;1/3,1/4,1/5;1/4,1/5,1/6;p=0.95,0.67,0.52'x=ApA=1/2,1/3,1/4;1/3,1/4,1/5;1

17、/4,1/5,1/6;p=0.95,0.67,0.53'x=Apcon d(A)2 (1)x1=fzero(fu nx1,-1)fun ctio n fx=fu nx1(x)fx=xA41+xA3+1;(2)x2=fzero(fu nx2,0.5)fun ctio n fx=fun x2(x)fx=x-s in( x)/x;(3)optio ns=optimset('Display','off);x=fsolve(fu n3,1,1,1',optio ns)q=fu n3(x)function q=fun 3(p)x=p(1);y=p(2);z=P(3)

18、;q(1)=si n(x)+y2+log (z)-7;q(2)=3*x+2Ay-zA3+1;q(3)=x+y+z-5;3 (1)to=o;tf=5;y0=1;t,y=ode23(fu n4,tO,tf,yO); t'y'function yp=fu n4(t,y)yp=-(1.2+si n(10*t)*y;(2)t0=0;tf=5;y0=1;t,y=ode23(fu n5,t0,tf,y0); t'y'function yp=fu n5(t,y)yp=cos(t)-y/(1+tA2);4x=fm inbn d(m ymin, 0,2);-mymi n(x)fun

19、 ctio n fx=mymi n(x)fx=-(1+x.A2)/(1+x.A4);5optio ns=optimset('Display','off);x,fval=fmi neon (fu n6,0,0,0,a,b,lb,ub)-fvalfun ctio n f=fun 6(x)f=-(sqrt(x(1)+(400-x(1)*1.1+(sqrt(x(2)+(400-x(1)*1.1-x(2)*1.1+sqrt(3)+(400-x(1)*1.1-x(2)*1.1-x(3)*1.1+sqrt(x(x4);思考練習(xí)1 (1)A=2,3,5;3,7,4;1,-7,1;B=1

20、0,3,5'C1=i nv(A)*BC2=ABL,U=lu(A);x=U(LB)(2)A=6,5,-2,5;9,-1,4,-1;3,4,2,-2;3,-9,0,2;B=-4,13,1,11'C1=i nv(A)*BC2=ABL,U=lu(A);x=U(LB)2 (1 )x1=fzero(fu nx1,1.5)fun ctio n fx=fu nx1(x)fx=3*x+si n( x)-exp(x);(2)x1=fzero(fu nx2,1)fun ctio n fx=fun x2(x) fx=x-1/x+5;(3)optio ns=optimset('Display&#

21、39;,'off); x=fsolve(fu n3,3,0',optio ns)q=fu n3(x)function q=fun 3(p)x=p(1);y=p(2);q(1)=xA2+yA2-9;q(2)=x+y-1;3 (1)to=o;tf=5;yo=o,i;t,y=ode45(vdpol,t0,tf,y0);t,yfunction ydot=vdpol(t,y);ydot(1)=(2-3*y(2)-2*t*y(1)./(1+tA2);ydot(2)=y(1);ydot=ydot'(2)t0=0;tf=5;yo=i;o;2;t,y=ode45(vdpoll,t0,tf

22、,y0);t,yfunction ydot=vdpoll(t,y);ydot(1)=cos(t)-y(3)./(3+si n( t)+5*y(1).*cos(2*t)/(t+1)A2)-y(2);ydot(2)=y(1);ydot(3)=y(2);ydot=ydot'4x=fmi nbn d(mymi n,O,pi);-mymi n(x)fun ctio n fx=mymi n(x)fx=-s in( x)-cos(x.A2);5x,y1=fmi nbn d(mymax,0,1.5);-yifun ctio n fx=mymax(x);fx=-(9*x+4*x.A3-12*x.A2);

23、unit7實(shí)驗(yàn)指導(dǎo)1 (1)format lo ngfx=i nli ne('s in (x)./x');I, n=quadl(fx,0,2,1e-10)(2)format lo ngfx=i nlin e('1./(x-0.3).A2+0.01)-1./(x-0.9).A2+0.04)-6');I, n=quad(fx,0,1,1e-10)2 (1)global ki;ki=O;l=dblquad(fxy,0,1,0,1)ki(2)f=i nlin e('abs(cos(x+y)','x','y');l=dblq

24、uad(f,O,pi,O,pi)3X=0.3:0.2:1.5;F=0.3895,0.6598,0.9147,1.1611,1.3971,1.6212,1.8325;trapz(X,F)4p=0:pi/5:2*pi;for n=1:3nDX=diff(si n(p),n)end5f=inlin e('si n(x)./(x+cos(2.*x)');g=i nlin e('(cos(x).*(x+cos(2*x)-si n(x).*(1-2.*si n(2*x)/(x+cos(2.*x).A2');x=-pi:0.01:pi;p=polyfit(x,f(x),5);

25、dp=polyder(p);dpx=polyval(dp,x);%求dp在假設(shè)點(diǎn)的函數(shù)值dx=diff(f(x,3.01)/0.01;%直接對(duì)f(x)求數(shù)值導(dǎo)數(shù)gx=g(x);%求函數(shù)f的導(dǎo)函數(shù)g在假設(shè)點(diǎn)的導(dǎo)數(shù)plot(x,dpx,x,dx,'.',x,gx,'-');%作圖思考練習(xí)2format Io ngfx=i nlin e('1./(1+x.A2)');I, n=quad(fx,-l nf,ln f,1e-1O)I, n=quadl(fx,-I nf,In f,1e-10) x=-100000:100000;y=1丿(1+x42);tra

26、pz(x,y)format short3(1)format Io ngfx=i nli ne('log(1+x)./(1+x.A2)');I, n=quad(fx,0,1,1e-10)format lo ngfx=i nli ne('sqrt(cos(t.A2)+4*si n( (2辻).人2)+1)');I, n=quad(fx,0,2*pi,1e-10)4f=i nlin e('4.*x.*z.*exp(-z.A2.*y-x.A2)');l=triplequad(f,0,pi,0,pi,0,1)5f=in lin e('si n( x

27、)');g=i nli ne('cos(x)');x=0:0.01:2*pi;p=polyfit(x,f(x),5);dp=polyder(p);dpx=polyval(dp,x);dx=diff(f(x,2*pi+0.01)/0.01;gx=g(x);plot(x,dpx,x,dx,'.',x,gx,'-')unit8實(shí)驗(yàn)指導(dǎo)1syms x y;s=xA4-yA4;factor(s)factor(5135)2syms x;f=(x-2)/(xA2-4);limit(f,x,2) sym x;f=(sqrt(pi)_sqrt(acos(x

28、)/sqrt(x+1);limit(f,x,-1,'right')3sym x;f=si n(1/x);diff(f,'x')diff(f,'x',2) sym x; f=(1-cos(2*x)/x;diff(f,'x')diff(f,'x',2)4sym x;f=sqrt(exp(x)+1);in t(f,'x')syms x y;f=x/(x+y);in t(f,'y')sym x;f=exp(x)*(1+exp(x)A2;in t(f,'x',0,log(2)s

29、ym x;f=x*log(x);in t(f,'x',1,exp(1)5sym x;s=symsum(-1)A(x+1)/x,1,l nf)sym y;z=symsum(yA(2*y-1)/(2*y-1),1,l nf)6sym x;f1=(exp(x)+exp(-x)/2;f2=sqrt(xA3-2*x+1);taylor(f1,x,5,0)taylor(f2,x,6,0)7syms x y a;x=solve('xA3+a*x+ 1=0','x')x=solve('si n(x)+2*cos(x)-sqrt(x)=0','x')x y=solve('log(x/y)=9','exp(x+y)=3','x','y')8syms n;x,y=dsolve('x*(D2y)+(1- n)*(Dy)+y=O','y(O)=O','Dy(O)=O','x')思考練習(xí)2syms x B1 B2 a bs1=2*(cos(x)A2)-(si n(x)A2;s2=si n( B1)*cos(B2)-cos(B1)*si n( B2);s

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論