1. 程式人生 > >Matlab數值運算(作業)

Matlab數值運算(作業)

【1】已知A = [1,4,7;10,13,16;19,22,25], k = 5。試求B = A + k、C = A - k、D = k - A。

         B = [6,9,12;15,18,21;24,27,30]

         C = [-4,-1,2;5,8,11;14,17,20]

         D = [4,1,-2;-5,-8,-11;-14,-17,-20]

【2】已知A = [1,4,7;10,13,16;19,22,25], k = 6。試求B = k .* A、C = k * A、D = A * k。

         B = [6,24,42;60,78,96;114,132,150]

         C = [6,24,42;60,78,96;114,132,150]

         D = [6,24,42;60,78,96;114,132,150] 

【3】已知A = [1,4,7;10,13,16;19,22,25], B = [6,6,6;3,3,3;1,1,1]。試求C = A .* B、D = B .* A。

         C = [6,24,42;30,39,48;19,22,25]

         D = [6,24,42;30,39,48;19,22,25]

【4】已知A = [1,4,7;10,13,16;19,22,25], B = [6,6,6;3,3,3;1,1,1]。試求C = A * B、D = B * A。

         C = [25,25,25;115,115,115;205,205,205]

         D = [180,234,288;90,117,144;30,39,48]

 【5】已知A = [1,4,7;10,13,16;19,22,25], k = 4。試求B = k ./ A、C = A .\ k、D = A ./ k。

B=[4,1,0.571428571428571;0.400000000000000,0.307692307692308,0.250000000000000;0.210526315789474,0.181818181818182,0.160000000000000]

C=[4,1,0.571428571428571;0.400000000000000,0.307692307692308,0.250000000000000;0.210526315789474,0.181818181818182,0.160000000000000]

D=[0.250000000000000,1,1.750000000000000;2.500000000000000,3.250000000000000,4;4.750000000000000,5.500000000000000,6.250000000000000]

【6】已知A = [1,4,7;10,13,16;19,22,25], k = 4。試求B = A / k。

B=[0.250000000000000,1,1.750000000000000;2.500000000000000,3.250000000000000,4;4.750000000000000,5.500000000000000,6.250000000000000]

【7】已知A = [1,4,7;10,13,16;19,22,25], B = [6,6,6;3,3,3;1,1,1]。試求C = A ./ B、D = B .\ A。

C=[0.166666666666667,0.666666666666667,1.166666666666667;3.333333333333334,4.333333333333333,5.333333333333333;19,22,25]

D=[0.166666666666667,0.666666666666667,1.166666666666667;3.333333333333334,4.333333333333333,5.333333333333333;19,22,25]

【8】已知c = [1,4,7;10,13,16;19,22,25], d = [1,0,0;0,1,0;0,0,1]。試求A = c \ d、E = d / c、G = d \ c。

A=[2.814749767106558e+14,-5.629499534213120e+14,2.814749767106560e+14;-5.629499534213121e+14,1.125899906842624e+15,-5.629499534213119e+14;2.814749767106563e+14,-5.629499534213120e+14,2.814749767106560e+14]

E=[2.814749767106558e+14,-5.629499534213120e+14,2.814749767106560e+14;-5.629499534213121e+14,1.125899906842624e+15,-5.629499534213119e+14;2.814749767106563e+14,-5.629499534213120e+14,2.814749767106560e+14]

G = [1,4,7;10,13,16;19,22,25]

 【9】已知a = [19,22,25],b = [1,4,7;10,13,16]。試求A = a .^ 2、B = b .^ 3。

A = [361,484,625]

B = [1,64,343;1000,2197,4096]

【10】已知a = [19,22,25],b = [1,4,7;10,13,16],d = 2。試求A = d .^ a、B = d.^ b。

A = [524288,4194304,33554432]

B = [2,16,128;1024,8192,65536]

【11】已知a = [1,4,7],b = [10,13,16],c = [1,2,3;4,5,6],d = [16,13,10;7,4,1]。試求A = a .^ b、B = d .^ c。

A = [1,67108864,3.323293056960100e+13]

B = [16,169,1000;2401,1024,1]

【12】已知a = [1,4;7,10],b = 2,c = [0.5] ,d = -0.2。試求A * B = a ^ b、A * C = a ^ c、AD = a ^ d、B * A = b ^ a、B*D*A = b .^ a。

AB = [29,44;77,128]

AC=[0.621206489076993 + 0.990834206288396i,1.015781054076987 - 0.346257204078352i;1.777616844634727 - 0.605950107137116i,2.906713860750212 + 0.211755497112104i]

 AD=[0.725490749883943 - 0.449837029837417i,-0.042477793017400 + 0.157200176632859i;-0.074336137780450 + 0.275100309107503i,0.629915715594793 - 0.096136632413485i]

BA = [9.829625594584617e+02,1.606715302849749e+03;2.811751779987059e+03,4.598071990870394e+03]

BDA = [2,16;128,1024]

【13】已知a = [1,4;7,10],b = a(1 + j2)。試求A = b'、B = b.'。

A = [1.000000000000000 - 2.000000000000000i,7.000000000000000 - 14.000000000000000i;4.000000000000000 - 8.000000000000000i,10.000000000000000 - 20.000000000000000i]

B = [1.000000000000000 + 2.000000000000000i,7.000000000000000 + 14.000000000000000i;4.000000000000000 + 8.000000000000000i,10.000000000000000 + 20.000000000000000i]

【14】用MATLAB函式計算向量a = [1,3,5]與b = [2,4,6]的點積a•b,並用空間解析幾何的基本原理公式加以驗算。

Dot = dot(a,b) = a•b = 44

a•b = a1*b1 + a2*b2 + a3*b3 = 1*2 + 3*4 + 5*6 = 44

【15】求向量a = [1,3,5]與b = [2,4,6]的叉積aXb。

Cross = cross(a,b) = [-2,4,-2]

【16】試計算矩陣a = [6,8,0;5,3,2;1,4,-3]與b = [1,1,-1,3;-1,-1,2,2;2,5,2,4;1,2,3,2]行列式的值。

Det(a) = det(a);

det(b) = det(b);

【17】試分別計算矩陣a = [1,1,1;2,-1,1;1,2,0]與b = [1,2,3;-1,0,1;3,3,4]的逆矩陣和偽逆矩陣。

Inv(a) = inv(a) = [-0.500000000000000,0.500000000000000,0.500000000000000;0.250000000000000,-0.250000000000000,0.250000000000000;1.250000000000000,-0.250000000000000,-0.750000000000000]

Pinv(a) = pinv(a) = [-0.500000000000000,0.500000000000000,0.500000000000000;0.250000000000000,-0.250000000000000,0.250000000000000;1.250000000000000,-0.250000000000000,-0.750000000000000]

Inv(b) = inv(b) = [-1.500000000000000,0.500000000000000,1.000000000000000;3.500000000000002,-2.500000000000002,-2.000000000000001;-1.500000000000001,1.500000000000001,1.000000000000000]

Pinv(b) = pinv(b) = [-1.500000000000000,0.500000000000001,1.000000000000000;3.500000000000003,-2.500000000000002,-2.000000000000002;-1.500000000000001,1.500000000000001,1.000000000000000]

【18】試計算矩陣a = [1,2,3,4;1,-2,4,5;1,10,1,2]與b = [3;-4;7;5]的秩。

Rank(a) = rank(a) = 2

Rank(b) = rank(b) = 1

【19】試計算矩陣A = [1,3,1,2;0,-1,1,3;0,0,3,5;0,0,0,3]的特徵值d、特徵值矩陣(對角矩陣)D與特徵向量矩陣V,並用式A•V = V•D加以驗算。

[V,D] = eig(A)

D = [1,0,0,0;0,-1,0,0;0,0,3,0;0,0,0,3]

V = [1,-0.832050294337844,0.647150228929434,-0.647150228929434;0,0.554700196225229,0.184900065408410,-0.184900065408410;0,0,0.739600261633639,-0.739600261633639;0,0,0,9.85345487381347e-17]

A•V = A * V = [1,0.832050294337844,1.94145068678830,-1.94145068678830;0,-0.554700196225229,0.554700196225229,-0.554700196225229;0,0,2.21880078490092,-2.21880078490092;0,0,0,2.95603646214404e-16]

V•D = V * D = [1,0.832050294337844,1.94145068678830,-1.94145068678830;0,-0.554700196225229,0.554700196225229,-0.554700196225229;0,0,2.21880078490092,-2.21880078490092;0,0,0,2.95603646214404e-16]

即A•V = V•D

【20】對矩陣A = [1,1,1;1,2,3;1,3,6]進行Cholesky分解。

 CholA = chol(A) = [1,1,1;0,1,2;0,0,1]

【21】試對矩陣A = [1,2,3;4,5,6;7,8,9]進行LU分解。

lu(L,U) = lu(A)

L = [0.142857142857143,1,0;0.571428571428571,0.500000000000000,1;1,0,0]

U = [7,8,9;0,0.857142857142857,1.714285714285714;0,0,1.110223024625157e-16]

【22】試對矩陣A = [9,4;2,8;6,7]進行QR分解。

[Q,R] = qr(A)

Q = [-0.818181818181818,0.399876007739215,-0.413131566006813;-0.181818181818182,-0.861611287393888,-0.473886208066638;-0.545454545454546,-0.312610249144193,0.777659418365766]

R = [-11,-8.545454545454545;0,-7.481658012203595;0,0]

【23】試對矩陣A = [9,4;6,8;2,7]進行奇異值分解。

 [U,S,V] = svd(A)

U =[-0.610499355638715,0.717438276656147,0.335518786289788;-0.664591243240893,-0.233605654481064,-0.709751278689935;-0.430823648575885,-0.656285545614965,0.619419297765762]

S = [14.935916399133795,0;0,5.188294644494102;0,0]

V = [-0.692537952203954,0.721381441927331;-0.721381441927331,-0.692537952203954]

【24】求多項式P(x) = x^3 - 2x - 4的根。

Root = roots(p) = [2.000000000000000 + 0.000000000000000i;-1.000000000000000 + 1.000000000000000i;-1.000000000000000 - 1.000000000000000i]

【25】已知多項式的根分別為1,2,3,4,5,試求此根對應的多項式。

  Roots = poly([1,2,3,4,5]) = [1,-15,85,-225,274,-120]

【26】求多項式P(x) = x ^ 5 - 15x ^ 4 + 85x ^ 3 - 225x ^ 2 + 274x - 120在指定點 x = 9 處的值。

Polyval = polyval(p,9) = 6720

【27】求多項式P(x) = 3x ^ 3 + 2x ^ 2 + x + 8與q(x) = 2x ^ 2 + x + 5的卷積並用解卷函式來驗證。

 Conv = conv(p,q) = [6,7,19,27,13,40]

 qq = deconv(Conv,p)

 所以 qq = q

【28】已知一傳遞函式F(s) = (s ^ 2 + 5s + 5) / (s ^2 + 4s + 3),將其分解為部分分式。

a = [1,5,5];b = [1,4,3]

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

z = [0.500000000000000;0.500000000000000]

p = [-3;-1]

k = 1

所以F(s) = (1 / 2)((s + 3) ^ (-1) + (s + 1)^(-1)) + 1

【29】求多項式P(x) = x ^ 3 - 2x - 4與Q(x) = 3x ^ 3 + 2x ^ 2 + x + 8的導數。

 p = [1,0,-2,-4];q = [3,2,1,8]

 p1 = polyder(p) = [3,0,-2]

 q1 = polyder(q) = [9,4,1]

【30】求多項式P(x) = x ^ 2 + 2x + 3在矩陣x = [1,2,3;4,5,6;7,8,9]時的值。

  c = [1,2,3]

  x = [1,2,3;4,5,6;7,8,9]

  p = polvalm(c,x) = [35,40,48;74,94,108;116,142,171]