1. 程式人生 > >matlab習題全部答案(3個小時的勞動成果),電信1601零掛科

matlab習題全部答案(3個小時的勞動成果),電信1601零掛科

4.19

根據已學以及自學完成以下內容
1、已知f1(s)=(s^2+3)(s+1)(s+4),求f1(s)=0的解。

>> solve('(s^2+3)*(s+1)*(s+4)=0')

ans =

         -4

         -1

  3^(1/2)*i

 -3^(1/2)*i

或者

>> a=[1,5,7,15,12];

>> roots(a)

ans

  -4.0000 + 0.0000i

   0.0000 + 1.7321i

   0.0000 - 1.7321i

  -1.0000 + 0.0000i

求f1在x點的值

>> syms s;f1=(s^2+3)*(s+1)*(s+4)

>> f2=expand(f1)

f2 =

s^4 + 5*s^3 + 7*s^2 + 15*s + 12

>> a=[1,5,7,15,12]

>> polyval(a,0)

ans =

12
2、已知f2(s)=(s^3+3)(s+5)(s^2+4),求f2(s)=0的解。

同上
3、求f2(s)/f1(s)的極點、留數、直項;

>> a=[1,5,7,15,12],b=[1,5,4,23,15,12,60];

a =

     1     5     7    15    12

>> [z,p,k]=residue(a,b)

z =

  -0.0317 + 0.0000i

  -0.0366 - 0.0402i

  -0.0366 + 0.0402i

   0.0737 - 0.2055i

   0.0737 + 0.2055i

  -0.0426 + 0.0000i

p =

  -5.0000 + 0.0000i

  -0.0000 + 2.0000i

  -0.0000 - 2.0000i

   0.7211 + 1.2490i

   0.7211 - 1.2490i

  -1.4422 + 0.0000i

k =

     []


4、求f1(1:100)、f2(6)的值

a=[1,5,7,15,12]

polyval(a,1:100)

polyval(b,6)

5、已知多項式係數p=[1 0 -2],寫出多項式,形式為ax^2+..+d;poly2str;

>> p=[1,0,-2];

>> poly2str(p,'x')

ans=

   x^2 - 2
6、生成100行1列的0~1的隨機數,賦值給e;

e=rand(100,1)

如要求生成a~b之間的隨機數,則

rand([m n])產生 m行,n列(0,1)範圍內均勻分佈的偽隨機數如果要求在區間(a,b)內產生均勻分佈的隨機數

r = a + (b-a).*rand([m n]));


7、y=x^2+x+e;其中x=1~100;求y的值;

syms x

>> y=x^2+x+exp(1)

y =

x^2 + x + 3060513257434037/112589990684262

>> a=1:100;

>> c=sym2poly(y)

c =

   1.0000    1.0000    2.7183

>> b=polyval(c,a);
8、使用polyfit對7題中的x、y擬合;
>> k=polyfit(a,c,2)

k = 1.0000    1.0000    2.7183

>> y1=poly2sym(k)

y1 =x^2 + (4503599627370159*x)/4503599627370496 + 1530256628717765/562949953421312怎麼才能擬合成x^2+x+exp(1)???
 

試做

p172 2:

>> clear

>> d=1e-5;

>> t=0:d:10;

>> t=t+(t==0)*realmin;

>> fx=sin(t)./t;

>> y=cumtrapz(fx)*d;

>> plot(t,y);

yt1=find(t==4.5);

y45=y(yt1);

P172 4:;

>> [email protected](x)exp(-abs(x)).*abs(sin(x));

>> format long

>> integral(fx,-5*pi,inf,'abstol',1e-9)

p172 5 ;

>> [email protected](t)sin(5*t).^2.*exp(0.06*t.*t)+1.8*abs(t+0.5)-1.5*t.*cos(2*t);

t=-5:0.01:5;

ezplot(ft,[-5,5]);

>> ad=fminbnd(ft,-2,-1)

4.26

以下都用符號計算完成。
1、顯示1000位有效數字的pi

 vpa(pi,100)
2、計算f1=5^0.5+2^0.3,

 f1=power(5,0.5)+power(2,0.3)
3、顯示f1,有效數字20位

vpa(f1,20)
4、已知f2(x)=(sinx)^3+2sinx+3,利用subs求x=[3 6 5]時的f2

 f2=(sin(x)^3)+2*sin(x)+3;

>> double(subs(f2,x,[2,3,4]))

ans =

   5.570421798320356   3.285050400854196   1.052936367403306
5、利用subs把f2轉化位y^3+2y+3

subs(f2,x,'y')
6、計算行列式[1 1 1 1;a b c d;a*a b*b c*c d*d;a*a*a b*b*b c*c*c d*d*d],並簡化

>> syms a b c d

A=[1 1 1 1;a b c d;a*a b*b c*c d*d;a*a*a b*b*b c*c*c d*d*d]

A =

[   1,   1,   1,   1]

[   a,   b,   c,   d]

[ a^2, b^2, c^2, d^2]

[ a^3, b^3, c^3, d^3]

>> B=det(A)

>> simplify(B)

ans =

(a - b)*(a - c)*(a - d)*(b - c)*(b - d)*(c - d)

7、因式分解1001, 因式分解 x^8 - 1

>> syms x

>> factor(x^8-1)

ans =

(x - 1)*(x + 1)*(x^2 + 1)*(x^4 + 1)

collect 合併同類項
expand 展開表示式
factor 因式分解

8、 將(x+1)^3、sin(x+y)展開
>> expand((x+1)^3)

ans =

x^3 + 3*x^2 + 3*x + 1

>> expand(sin(x+y);

ans =

cos(x)*sin(y) + cos(y)*sin(x)
有能力的自學:
1、求sinx/x當x趨向0的左極限與右極限

limit(sin(x)/x,x,0,'left')

limit(sin(x)/x,x,0,'right')
2、計算  x*x/(1-cosx) 當x趨於0的極限

 limit(x*x/(1-cos(x)),x,0)

ans =

2
3、對 x*x/(1-cosx) 求二次導數 

simplify(diff(x*x/(1-cos(x)),x,2))

ans =

(x^2*cos(x) - 2*cos(x) - 4*x*sin(x) + 2*x^2 + 2)/(cos(x) - 1)^2

5.10

1 求解微分方程 y''+3y'+2y=sinx;

>> dsolve('D2y+3*Dy+2*y=sin(x)','x')

ans =

sin(x)/10 - (3*cos(x))/10 + C2*exp(-x) + C3*exp(-2*x)
2 計算  x*x/(1-cosx) 當x趨於0的極限

>> y= x*x/(1-cos(x))

-x^2/(cos(x) - 1)

>> limit(y,x,0)

2

3 xsin(x)的積分上限  2^0.5   下限 2

>> double(int(x.*sin(x),x,power(2,0.5),2))

ans =

0.9744
 
7 求級數和 1/1/1 + 1/2/2+ 。。。。。

symsum(1/x^2,x,1,inf)

ans =

pi^2/6
  



9 taylortool 檢視 學習------->taylor逼近計算器

10 funtool 檢視 學習------->圖示化符號計算器

5.17

 2、畫出間距0.05,[0,2pi] 範圍之內的sin曲線的離散圖形

syms x

>> x=[0:0.05:2*pi];

>> plot(sin(x))

 plot(x,sin(x),'r-','LineWidth',3)

3、利用已學知識,畫出下面的圖形:

t=[0:0.01:3.5];

plot(t,sin(t).*sin(9*t),'r--')

xlabel('X軸時間t'),ylabel('y軸位移s')

text(1.5,0.8,'優美的曲線 s=sint.sin9t')

text(1,0.35,'y(1)=0.35')                                                       

title(['曲線 s=sint.sin9t'])

legend('sint.sin9t');

5、已知橢圓(x-3)^2/6^2+(y-2)^2/8^2=1,畫出該橢圓,注意使用axis equal,  (help axis)

 >> t=0:0.01:2*pi;

 x=3+6*cos(t);

 y=2+8*sin(t);

 plot(x,y)

>> axis equal

6、已知x=0:0.2:2; y=5*x+rand(1,11); 利用已學知識polyfit以及plot,畫出下面的圖形:

>> clear

x=0:0.2:2;

y=5*x+rand(1,11);

plot(x,y);

polyfit(x,y,1);

plot(x,y,'r.');

polyfit(x,y,1);

 ans=

4.8651    0.6786

>> plot(x,4.8651.*x+0.6786)

>> plot(x,y,'r.');

>> hold on

>> plot(x,4.8651.*x+0.6786)

5.31日作業

1、已知z=x^2+y^2+3xy,x,y~~[-2 2], 畫出曲面, 網線圖

syms x y z

>> x=-2:2

>> y=x;

>> [X Y]=meshgrid(x,y);

 Z=X.*X+Y.*Y+3*X.*Y

 mesh(X,Y,Z);

surf(X,Y,Z);

2、例 5.3--5

>> [X Y Z]=sphere(40);

>> colormap(jet);

>> subplot(1,2,1),surf(X,Y,Z),axis equal off,shading interp

>> light('position',[0 -10 1.5],'style','infinite')


3、習題5.5

t=0:pi/100:2*pi;

x=sin(t);

y=cos(t);

z=t;

plot3(x,y,z,'-b','linewidth',3);

box on  


4、習題5.6

>> x=-3:0.1:3;

>> y=-3:0.1:3;

>> [X Y]=meshgrid(x,y);

>> Z=4*X.*exp(-X.^2-Y.^2);

>> mesh(X,Y,Z)

>> hidden off

axis([-3,3,-3,3,-2,2])
 

6.7

p236
1、習題1

 >> sum=0;

>> for i=0:1000000

sum=sum+power(0.2,i);

end

>> sum

sum =

    1.2500

>> sum=0;

>> i=0;

>> while i<=1000000

sum=sum+power(0.2,i);

i=i+1;

end

>> sum

sum =

    1.2500
2、程式設計寫出水仙花數。

for i=100:999

a1=fix(i/100);

a2=mod(fix(i/10),10);

a3=mod(i,10);

  if i==a1^3+a2^3+a3^3

     disp(i)

  end

end


3、編寫一個氣泡排序函式,從小到大。

for ii=1:(r-1)

       for jj=1:(r-ii)

           if  A(jj)>A(jj+1)

               s=A(jj);

               A(jj)=A(jj+1);

               A(jj+1)=s;

            end

        end

end