星期四, 11月 02, 2006

MATLAB課堂作業: 作業四

1. Two vectors A=3i +5i +10k and B=5i -6j +2k are both passing through an origin. Find the unit vector that is perpendicular to both vectors A & B.

ANS:
可以用外積的公式算出與兩向量垂直之向量
若A=a1i+a2j+a3k且B=b1i+b2j+b3k
則垂直向量C=A×B=(a2*b3-a3*b2)i+(a3*b1-a1*b3)j+(a1*b2-a2*b1)k
可以cross指令計算得出:
>> A=[3 5 10];B=[5 -6 2];
>> C=cross(A,B)

C =

70 44 -43

故向量C=70i+44j-43k

2. A=randn(10,10). Find mean(A), median(A,2), std(A), std(A,1,2). Explain the results.

ANS:
>> A=randn(10,10)

A =

-1.1878 -1.1859 0.1286 0.8057 -0.3306 -0.1199 0.4694 1.0184 -0.4650 1.5532
-2.2023 -1.0559 0.6565 0.2316 -0.8436 -0.0653 -0.9036 -1.5804 0.3710 0.7079
0.9863 1.4725 -1.1678 -0.9898 0.4978 0.4853 0.0359 -0.0787 0.7283 1.9574
-0.5186 0.0557 -0.4606 1.3396 1.4885 -0.5955 -0.6275 -0.6817 2.1122 0.5045
0.3274 -1.2173 -0.2624 0.2895 -0.5465 -0.1497 0.5354 -1.0246 -1.3573 1.8645
0.2341 -0.0412 -1.2132 1.4789 -0.8468 -0.4348 0.5529 -1.2344 -1.0226 -0.3398
0.0215 -1.1283 -1.3194 1.1380 -0.2463 -0.0793 -0.2037 0.2888 1.0378 -1.1398
-1.0039 -1.3493 0.9312 -0.6841 0.6630 1.5352 -2.0543 -0.4293 -0.3898 -0.2111
-0.9471 -0.2611 0.0112 -1.2919 -0.8542 -0.6065 0.1326 0.0558 -1.3813 1.1902
-0.3744 0.9535 -0.6451 -0.0729 -1.2013 -1.3474 1.5929 -0.3679 0.3155 -1.1162

>> mean(A) %結果顯示每一行的平均值

ans =

-0.4665 -0.3757 -0.3341 0.2245 -0.2220 -0.1378 -0.0470 -0.4034 -0.0051 0.4971

>> median(A,2) %結果顯示每一列的中間值

ans =

0.0044
-0.4545
0.4915
-0.2024
-0.2061
-0.3873
-0.1415
-0.4096
-0.4338
-0.3712

>> std(A) %結果顯示每一行的標準差,其計算式為以(n-1)為底的公式做計算

ans =

0.9150 0.9908 0.7798 0.9822 0.8485 0.7584 0.9899 0.7716 1.1289 1.1608

>> std(A,1,2) %結果顯示每一列的標準差,其計算式為以n為底的公式做計算

ans =

0.8629
0.9447
0.9378
0.9868
0.9209
0.8240
0.8131
1.0327
0.7426
0.9075

3. Prove that exp(i*theta)=cos(theta)+i*sin(x) using matlab commands.

ANS:
>> theta=[30 40]*180/pi; % 以角度為30度和40度做驗證,先換算為弧度
>> a=exp(i*theta);
>> b=cos(theta)+i*sin(theta);
>> isequal(a,b)

ans =

1

故exp(i*theta)=cos(theta)+i*sin(theta)得證
p.s. 兩個角度算出來的值分別為(-0.9122 - 0.4098i)和(0.0393 - 0.9992i)

4. Let R=eye(3)*5+4*ones(3)i. Find abs(R), angle(R), real(R) and imag(R).

ANS:
>> R=eye(3).*5+4*ones(3)*i

R =

5.0000 + 4.0000i 0 + 4.0000i 0 + 4.0000i
0 + 4.0000i 5.0000 + 4.0000i 0 + 4.0000i
0 + 4.0000i 0 + 4.0000i 5.0000 + 4.0000i

>> abs(R)

ans =

6.4031 4.0000 4.0000
4.0000 6.4031 4.0000
4.0000 4.0000 6.4031

>> angle(R) % 弧度

ans =

0.6747 1.5708 1.5708
1.5708 0.6747 1.5708
1.5708 1.5708 0.6747

>> angle(R)*180/pi % 角度

ans =

38.6598 90.0000 90.0000
90.0000 38.6598 90.0000
90.0000 90.0000 38.6598

>> real(R) % the real part of the elements

ans =

5 0 0
0 5 0
0 0 5

>> imag(R) % the imaginary part of the elements

ans =

4 4 4
4 4 4
4 4 4

沒有留言: