Matlab程序設計與應用第二版劉衛(wèi)國課后實驗答案_第1頁
Matlab程序設計與應用第二版劉衛(wèi)國課后實驗答案_第2頁
Matlab程序設計與應用第二版劉衛(wèi)國課后實驗答案_第3頁
Matlab程序設計與應用第二版劉衛(wèi)國課后實驗答案_第4頁
Matlab程序設計與應用第二版劉衛(wèi)國課后實驗答案_第5頁
免費預覽已結(jié)束,剩余9頁可下載查看

下載本文檔

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

文檔簡介

1、實驗一 :T1:第一小題z1 =2*sin( 85pi/1 80) /(1+exp(2 )第二小題x=2 ,1+2i; 0、 45, 5;z2=1/2*log(x+s qr t(1+x、人 2);z 2 %第三小題a =3、0:0、1:3、 0;z3=1 /2 * (ex p (0、3*a)- e xp (-0、3 *a)卜 sin(a+0、 3)log( (0、3 +a) /2)%第四題9, 7, 0; 4,1 3,11 ;C =A* BD =C(3:5, 2 : 3)T4-1:a =100: 9 99;b=fi nd( r e m (a,21) =0 );c=1 ength(b )T42:

2、a = in p Ute請輸入一個字符串:', sO ;b = find (a= A/ &a ='ZO ;a( b)=;disp( a) ;實驗二:t =0 :0、5 :2、5z 4=( t>=0 & t 1 )、*( t、人2) +(t>= 1&t<2)、* (t、人 2 1) +(t=2&t<3 )、* (t、 人 22 * t+ 1)T2:A =12 , 3 4, 4;34, 7, 8 7; 3 ,65,7B = 1 , 3, 1;2, 0, 3;3, -2,7disp ( 'A +6* B=') ;

3、di sp( A+6* B);disp( A'B I=');dis p(A-B+eye(3);dis p('A*B= ');dis p(A*B);d isp( 'A、 *B =');disp( A、 *B) ;d isp ('AG 'disp (A 人 3);disp ('A、人 3=');di sp (A、人3);d isp('A/B=') ;di sp(A/B) ;disp ( 'AB=' ) ;dis p (BA);disp(/A,B=');di sp(A,B );d

4、i s p ( ' : A(1,3 ,: );B2=');d i sp (A (: 1,3,:)砂2);T3:z=1 :25;A=res hape (z, 5,5) 'B= 3, 0, 16; 17,6 ,9;0 ,23, 4;T1 :E=eye(3), R=rand(3, 2) ,O=zero s(2,3), S= dia g (1, 2);A=E,R;O,Sdisp (A2=');di s p (A 2);disp('E ,R +RS O, S2:');B= E, R+ R*S; O,S 人2:T2:H=hi 1 b(5)P=pasc al

5、(5 )H h=de t( H)Hp=de t(P)Th=co nd( H)Tp =co nd (P)a =ab s (Th- 1 );b = abs ( T p - 1);i f a > bdisp ('帕薩卡矩陣 P 性能更好 ') ;e1s e i fa<bdisp (/希爾伯特矩陣 H 性能更好' ); elsedispC兩個矩陣性能相同');en dT3:a=1: 25;A=res ha pe(a,5,5)dis p('行列式得值:');disp(de t (A);dis p( '矩陣得秩:');disp(

6、rank(A );d i s p(' 矩陣得跡 :' );disp(tr ace( A);disp( '矩陣得范數(shù): );dis p(nO rm(A) );T4:A=2 9, 6, 18;20,5 ,12 ;8,8, 5V,D =eig (A)T5:A= 1/2, 1/3, 1/ 4 ;1/3, 1/ 4, 1/5; 1/4,5, 16B= : 0、9 5,0、6 7, 0、5 2 'X1=A BB( 3) =0、 53X2=ABdis p ('系數(shù)矩陣 A得條件數(shù):/);disp(con d(A) ;T6:1/the sdisp('the sc

7、Or e is not reas ona b le);s=i n p ut( / pie as e en tercore: /) ;endi f (s>= 90&S < = 10 0);d isp( 'A');el s eif(s > = 8 0 & s <90);d isp()B/) ;e1 se if(s =70&sV 80);di sp( ) C);elseif (s> = 60 & sV 70);dis p( 'D');el s edis p('E') ;endT 2 swit

8、ch :a=1:25;A =r e sha pe ( a, 5,5 ) di sp( ' B1=sqrtm)('A);B 1=sq r t m (A)disp( B2 =sq rt( A) );B2= sq r t(A)di sp( 'B1*B 1');B1* B1disp(/ B2、 *B2) ;B2、 *B2實驗三 :T1:X =5、0:2: 5、0: length(X) ;(x (i) <0) &(x(i) = -3)yel s ei& (x(i)=2) y(i) elsey (i)=x(i)人2 x( i)-1 ;endfor i=

9、1if(i)= x( i)八 2 +x (i) 6;f (x(i)>=0)&(x(i)V5)& (x (i)=3);=x(i)A2 5* x(i)+6;ends=input ('p lease en ter ');whi 1 e (s < 0| | sdisp ( 'the reasonab1 e' );s=input('p 1 ease re:' ); end switc h fix(s/1 0 ) cas e9,1 0disp( A'); case8 di s p CE '); c ase 7 d

10、isp ('C ' case 6 dis p(' D'); ca se 0, d isp(' E/ e nd T 3: t =inp ut i ft>120SCO re :);100) scoren1, 2,3, 4,5);'請輸入工時s nO tt h e sc ome=');yT2 if:s =i npu t(' pie a se ent er the s c ore:,);while (SV 0| |s100)w=120 *84+(t-120) * 1、 15* 84;elseif t < 60w =t * 8

11、4 -70 0 ;elsew= 8 4 *t;pii= sqT12:rt(6 m)endd isp ('應發(fā)工資為:); di sp(w);T 4:a=10 +f1 oor(rand(1)* 89)b =1 0 + f loor( ra nd (1) * 89)s=inp ut (/ 請輸入 + 或一或 * 或 /' , ' s');w hi 1 e ( s='+ ' & s -,&& s -*'&&s =' /')d isp ('輸入得符號錯誤, 請重新輸入 ')

12、;s=inp ut (/ 請輸入 + 或-或*或/' , 's'); end switch scase ' +'c=a+ b;c ase ''c=ab;ca se* 'c=a* b;ca se ' / 'c =a/b ;t(/請輸入 n: (1 :n)、人 2;s=sum( m ); pii=sq rt(6 s)T2:n=inpum=1 、 /n=1 0 00;y=0; for i=1 : n;y = y+ 1/ (2 * i1ifendT 3:endcT5:A =n=inp u t('請輸入 n :

13、9;);whi 1 e (n <1)d isp ('輸入得n有誤,請重新輸入/ ); n=i npu t ('請輸入 n:');rand(5, 6)if n >5B=A( 5, :)eIseB= A(n,:)E nd實驗四 :T1:n=in p ut (/ 請輸入 n:');m =0;for i=1 : n;m=m+1/iA 2;'););y >= 3d isp ( ' 最大 n i 1disp ('對應得值為:);y 值為 :' ); y1/( 2 i-1)break;dta =in put('請輸入

14、a:');b =inp ut ('請輸入 b:');x (1)= a/(1、0 +b) ; i = 1;x (2 b) ;whil e (a b s (x (i+ 1) x(i)>1& i 50 0)for mIon gi =i+1 ;x(i+1)= a/(x (i) + b);endr仁(b+s qrt(b 人 2+4*a) /2;r2 =( -b s qr t( b 2+ 4 * a)=a / (x(i)0、00 0 0d is p (' x ' ,nm 2st r (i+ 1 ),n um2st r(x( i+1), 8) );dis

15、p ('x',num 2 str( i),'=,num 2str (x( i),8 );di sp('r1=,nu m2s tr( r1,8),', r2=', num2str(r 2,8 );fo r mat shortT4:f(1 )=1;f( 2)=0;f(3 )=1 ;i=4;w h il e (i<= 10 0)f(i) =f( i1 )-2* f( i2) +f( i3 ); i=i+1;enden denf=f +i * (i + 1); dfx:fuf=1 、A*9、8' =/ );%挑選出1 0 99f m a x

16、= max (f )fmin = min (f) fs um=s um(f) fp= 1 engt h(f in d( f> 0) fn=length (fin d (fv0 ) fO=lengt h( f i nd (f= =0) T5:j =0; s= 0;for i=3:50m=i*( i-1)1;i f i s prime (m)= =1s = s +m ;j =j +l;endendd i sp('親密數(shù)得對數(shù):',nu m 2s tr (j):); dis p (所有親密素數(shù)之與: ',n um2str( s ) );實驗五:f n1: func t

17、ion f = fn1 ( n)f= n +10 * l o g( n、人 2 +5); fn2:f un ctio n f=f n2( n) f = 0;f or i= l: n nction f=fx ( x)/ (x 2)、八 2 + 0、1) +1、/ (x3 )、 4+0、0 1);Tl :x =in p ut('請輸入一個復數(shù):');fe =exp (x)f lg= log( x) fsin=sin( x) f co s= cos(x)T2:m 1=in p ut ('請輸入m 1/);m2=input ()請輸入m 2:' t=input (

18、9;請輸入 th et a:);A=m1*cos(t ), -m1,-si n(t), 0;m 1 * sin(t), 0 ,、co s( t) , 0 ;0,m2, sin (t), 0; 0, 0, C o s(t) ,1B= 0, m1 * 9、8,0,m2dis p(' al ,a2 ,N 1,N2: d i s p(AB :'T 3: j=1 ; n= l;k =1;for i=10:99 中所有得素數(shù)if isprime(i)=1m(j)=i;j=j1;endendf o r t=1:le n gth ( m);s( n)=l 0* r em(m(t ), 10)f

19、ix(m (t )/10); %挑選出得素數(shù)進行位置交換if i sp rim e(s(n) = = 1%再挑選出交換絕對素數(shù)r( k)= m(t);k=k+l ;endn=n+ l ;enddisp ('所有兩位絕對素數(shù):', num2str(r) )T 5:y 1=f n 1 ( 4 0 ) /(f n 1(3 0 ) +fn1( 20 )%函數(shù)調(diào)用y2 =f n2(40)( fn 2( 30)fn2 (20)實驗六 :T1: x=linspa ce (0, 2*pi,101 );y=(0、5+ 3* sin(x)、/ (l + x、人2)、* c os ( x) ;plo

20、t( x, y) ;T2: x=1in sp ace(0, 2*p i,10 0);y1=x、人 2;y2=cos( 2*x);y3 =y1 、 *y2 ;subplot(2,2, 1);plot(x,y1,r':',x,y2, 'y', x, y3, 'b、sub pl o t(2,2,2);el sepl ot(X,y 1,'r:');y =y,1 /2 *l og(x0sqr t(1s u b plot ( 2,2,3);+ x 0 人 2);p lot(x,y2, ' -y');e ndsubplot(2 ,2,

21、4);en dpl ot( x,y 3, 'b、 ');subplot (1, 2,1);T 2-3 :pl ot(X, y);x=lin spa ce(0 ,2*pi,1 0 );fo r i =1:l ength( x)y仁X、人2 ;ifX(i) <=0y2 =cos(2 x);y(i)= (x (i)+sq rt( pi ) / e x py 3 = y1、*y2 ;(2 );sub plot (3, 4,1);elseb ar( x, y1,r);axis( 0, 7 ,0, 40:);y( i) =12 *l og(x (i)sqrs ub pl ot(3,

22、4 ,2);t (1+x(i) A2);stairs(x, y1,'y) ;aX is( 0,7,0, 40);endsubp lo t(3, 4, 3);e ndstem(x, y1,b' ') ;aX is(0,7 ,0 ,40);subp lot(1,2, 2);');y =y,(xO+sqrt(pi) /exp( 2);su bp l 0 t (3,4, 4);fill( x,y1, 'g ') ;axis (0, 7,0 ,40) ; sub plot( 3, 4,5);bar(x, y2,r' );ax(is 1,7,1, 1

23、:) subplot( 3, 4,s tair s(X ,y2,'1:);subpl ot (3, 4,7);ste m( x, y2, 'b )'1: );sub pl ot( 3,4,8);fil l(X,y 2,'g);sub p lot (3 ,4, 9);bar (x,y3,r') ;aXi s(0,7 ,-30,50) ; subplot (3, 4,10 );sta irs(x,y3, )' ;yaxi s(0, 7,-30 ,50:); su bplot(3 ,4, 11);s tem( x,y3 ,'b') ;a

24、xi sub pl o t(3, 4 ,12);fill(x,y3,g);50);T3:6);y);'axis(1, 7, -1,;a xis (:-l ,7, - 1,axi s (:-1,7,- 1 ,1:);s (0,7, -30,5 0:);a x is ( 0, 7 ,-30,x=li nsp ace( -5,5,1 y=:;for X0 =x;i f x0 =0;0 0);plo t (x, y );T4:a=i n pu t C 請輸入 a:'); b=i np ut ('請輸入 b: / ); n= i npu t ('請輸入 n :')

25、;t he ta=0: 0、0 0 1 :2*p i; y=a、 *sin(b+n 、 *theta) ; polar(thet a,y);T5:X =lin s pace( 5 ,5, 2 1);y= l in s pace(0,10,3 1);:x, y: =me s hg rid (x,y);z =cos(x)、*c os (y)、* exp( sq r t ( x、 人2 + y、人 2)/4)s u bp lot (1,surf( x,y,z): sub p l o t(1, co ntour 3(x,y,T6:s=0:pi /2;t=0:3pi/2; s,t: =mes hgri

26、d(s,t) ;x= c os(s)、* c os (t );y= c os ( s)、* s i n (t); z=sin( s) ; s urf(X ,y, z);2, 1);2, 2);z);s h a d in g in terp ;實驗八:T1:?A=rand(1, 30000);dis p (均值為 :') ;mean (A)di sp('標準方差為:/);s td ( A)di s p('最大元素為:');ma x( A)d i s pC最小元素為:');min(A)k=find ( A0、 5) ; b= le ngd h( k);dis

27、p ('大于 0、 5 得隨機數(shù)個數(shù)占總數(shù)得百 分比:');sp rintf ('% f % % , b / 3 0 0 )T2: ?P =4550* ran d(100, 5) disp('最高分及序號:/ );Y,U: =max(P,: ,1) disp ('最低分及序號: ' );Y1, U1:= min(P,: ,1)di sp ('每門課平均分: ') ;mean( P,1)di sp( '每門課得標準方差:');std(P ,0, 1)s=sum(P,2) ;d i s p( '總分最高分: &

28、#39; );Y2, U2: =maX( s, : ,1) di sp( '總分最低分: );Y3, U3=min(s, 1)zcj , X sxh:end')% descT3:=sord ( s ,1 ,' descen d降序p=p olyfit ( x, y, 5) x1=1:0、 01:101;y1=log10(x1);y 2 =poly V al (p, x1);plot( X 1, y1,' r -' ,x1 y 2 ,'£')T 5:P1=1,2,4,0 ,5;P2=0 ,0, 0, 1,2;P3 =0,0 , 1

29、,2 , 3:;P4= c onv( P2 , P 3);sp 1 = length( P 1);sp2=len gth( P4);P = z er os (1 ,sp2 s p1 ), P1: + P4x= roots(P)A=-1, 1、 2, -1、 4;0、 75,2,3、 5; 0, 5 ,2、 5;Ax=p o l y val (PA)A A=po l y valm(P, A)實驗九 :T1 :f= i nline( e d * X 人2;0 2 6*x : i=1 ;x=1;whi 1 e x<=3、(:x xA 2 xA 3)12* x 3') ;h= 6:2:1

30、8; t1=1 8、 0,2 0、 28、 0, 24、 0;t 2 = 1 5、0,1 9、32、0, 30、 t=6、 5:2:1 T1=interp1(h,tT2=inde rpT4:0,22、0,25、0, 24、 0,28、0;7、5;1 ,t, 'sp1 ine ')1(h, t2,d , 'ps10 ,30、0,0,34、 0,ine )'x=1 : 10:101;y=log1 0(x) ;01g( i) =f(X);i =i+1;x=X +0、0 1 ;endd x=di f f (g)/ 0、01;dX (1)dx(1 01 )dx(lengt

31、h(g)1)T2:f1 =in line (s qrt (co s(t、人 2)+4*sin(2* t )、人 2+1)')f2=in lin e('log(1+x)、( 1X、 A2) ')pi )pi)I 1 = quI2=q u a dT3 :ad(f1,0,(f 2, 0,22A=6, 5, 2;3,9,0, 2: ;B=4, 13,1,1 1 ;'x1=A B-2, 5;9,-1 ,4 , 1;3,4,2 ,bet a2)4*x人 2+8* x+3 )/ (2 * x +syms a b ce f g h k;0,0 ; 0 ,0 ,1; 0 ;1,0

32、, 1:;g,h,k;t, 1)X p( -xA2 y 人 2 -X* y);/d i ff (f5 , y,1)%f5,x,1),y, 1)T1::L ,U=I u( A);( LB)Q,R =q r (A);(QB)f u n:f u n ction F = fu n( X) x=X(1);y =X( 2);z =X (3);F (1)=sin(X)+ y2+l o g (z)7 ;F(2)=3*x+ 2 Ay z 人3+1 ;F(3) =x+y+z-5;T5:f =inl ine( '3*x+sin(x) exp(x) ') ;fzero( f,1 、5)X=fso Iv

33、e ('讓 n', : 1 1 1',o pt i m set CDi sp l ay/, ' f f 0 )實驗十:T1:x= sym('6 'y =sym(' 5'z=(x+ 1) /(sqrt( 3 +x) sq r t (y )T2:Sy m s x y;t =sym ('51350 ;factor(xA4 yM) factor(t)T 3:s y ms betal b eta2 x;Sim pli f y( sin( b e t a 1) * co s(beta2) cos (beta1) sins i m p li fy(1)T4:d p 1= 0,1, 0;1 ,p2=1,0,0 ;0,1, A = : a,b, c;d,e,f;B= p 1*p 2 * AB1= inv (B)B1* B;tr i l( B )d et (B)T5:sy ms x t a yf1=(X *( eX p(sin(x) )+1 )2*(e xp(t an(x)1) )/sin ( x)

溫馨提示

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

評論

0/150

提交評論