星期四, 10月 26, 2006

html語法: 上標與下標

上標
a2+b2=c2
語法 : a2+b2=c2

下標
a2+b2=c2
語法 : a2+b2=c2

星期五, 10月 13, 2006

Auditory blog

網址 podcast.com

星期四, 10月 05, 2006

MATLAB課堂作業: 作業二

1. During SARS period, people who passed the airport gate should have their temperatures measured. Suppose that B is the recorded body temperatures in Fahrenheit and B=[98 100 102 104 98.4 98.2 98.5 101 102 99.5]. Please workout a program to do: a) Converse the unit of B into Centigrade b)Decide who got the temperature? Design a matrix D to show that "1" for the one who has a fever (>38C) and "0" for the normal.

ANS:
>> % Quesiotn 1
>>% 題旨:將華氏溫度轉換為攝氏溫度,並且定義出溫度大於38度c者為1
>> B=[98 100 102 104 98.4 98.2 98.5 101 102 99.5]; % 所有被測者的華氏體溫
>> c=(B-32)*5/9 % 將華氏溫度換算為攝氏溫度

c =

Columns 1 through 8

36.6667 37.7778 38.8889 40.0000 36.8889 36.7778 36.9444 38.3333

Columns 9 through 10

38.8889 37.5000

>> D=c>38 % 將攝氏溫度大於38度c者定義為1,得一新矩陣D

D =

0 0 1 1 0 0 0 1 1 0
>> % 執行結果: 換算後的攝氏溫度為[36.6667 37.7778 38.8889 40.0000 36.8889 36.7778 36.9444 38.3333 38.8889 37.5000]; 定義體溫大於38度c的matrix D=[0 0 1 1 0 0 0 1 1 0]
>> % 討論: 定義出高體溫者之後,若現實上受測者有編號,則可以利用尋找索引值的方式輕易找出高體溫者為誰

2. There are two matrices A and B, in which A=[ -10 8 6 4 -5 20] and B=[2 8 5 10 -6 3]. Find D using both Matlab commands .(a) D= (A>B) (b) D= (A>5) (f) D=A+B.

ANS:
>> % Quesiotn 2
>> % 題旨:比較矩陣A與矩陣B
>> A=[-10 8 6 4 -5 20];
>> B=[2 8 5 10 -6 3];
>> D=A>B % 矩陣A與矩陣B一對一比較,A>B者定義為1,其餘為0

D =

0 0 1 0 1 1

>> D=A>5 % 矩陣A中數值>5者定義為1,其餘為0

D =

0 1 1 0 0 1

>> D=A+B % 將矩陣A與矩陣B相加

D =

-8 16 11 14 -11 23

>> % 執行結果: (1) D=[0 0 1 0 1 1] (2) D= [0 1 1 0 0 1] (3) D=[-8 16 11 14 -11 23]
>> % 討論:矩陣A與矩陣B排列相同,因此兩者可以直接做比較與計算

3. Suppose that x=[10 20 30] and y=[1 4 6], Calculate the following combinations using Matlab commands:(a) A= 3x +y (b) B=5y/x (c) C=4x2y (d) D=sin(x)cos(y) (e)5x sin(2y)

ANS:
>> % Quesiotn 3
>> % 題旨:進行矩陣x與矩陣y之計算
>> x=[10 20 30];
>> y=[1 4 6];
>> A=3*x+y

A =

31 64 96

>> B=5*y./x

B =

0.5000 1.0000 1.0000

>> C=4*2*y

C =

8 32 48

>> D=sin(x).*cos(y)

D =

-0.2939 -0.5967 -0.9487

>> E=5*x.*sin(2*y)

E =

45.4649 98.9358 -80.4859
>> % 執行結果: A= [31 64 96], B= [0.5000 1.0000 1.0000], C=[8 32 48], D= [-0.2939 -0.5967 -0.9487], E= [45.4649 98.9358 -80.4859]
>> % 討論:重點在於元素對元素的計算符號是在矩陣的計算符號之前加上"."

4. A set of resistors are expressed in an array as R=[ 10 30 200 400]ohms. Write a M-file program to calculate the equivalent resistance if (a) all the resistors are in series (b) all of the resistors are in parallel.

ANS:
% Quesiotn 3
% 題旨:撰寫一個計算多個電阻分別串聯與並聯後之總電阻的M-file
R=[10 30 200 400];
R1=sum(R) % 串聯後之總電阻R1為四個電阻之總合 R1=r1+r2+r3+r4
R2=1/sum(1./R) % 並聯後之總電阻R2=1/(1/r1+1/r2+1/r3+1/r4)
>>% 在command window下執行M-file
>>% 執行結果: 串聯後之總電阻R1為640歐姆; 並聯後之總電阻R2為7.1006歐姆
>>% 討論:計算R矩陣中各個element的倒數不能單純以1/R指令執行,而需在/之前加上.才可順利算出數值

5. Suppose matrix A=1:24, please reform A into matrices B in size 3x8; C in size 6x4; D in size 2x12.

ANS:
>>% Question 5
>>% 將矩陣A(1x24)轉置為B (3x8), C(6x4), D(2x12)三種不同排列方式之矩陣
>> A=[1:24];
>> B=reshape(A,3,8)

B =

1 4 7 10 13 16 19 22
2 5 8 11 14 17 20 23
3 6 9 12 15 18 21 24

>> C=reshape(A,6,4)

C =

1 7 13 19
2 8 14 20
3 9 15 21
4 10 16 22
5 11 17 23
6 12 18 24

>> D=reshape(A,2,12)

D =

1 3 5 7 9 11 13 15 17 19 21 23
2 4 6 8 10 12 14 16 18 20 22 24
>>% 執行結果:如上所示之B、C、D三矩陣
>>% 討論:使用reshape(A,m,n)方式將陣列A的元素由上到下,由左到右的次序重新排列成一個新的m×n的矩陣。使用reshape函數時,重排後矩陣元素的個數必須與原矩陣相同。