10/03/2006

problem#02黃聖峰

%------------------------程式碼----------------------------------%
close all;
clc;
%-----------------------第一題 ----------------------------------%
%----------這是個温度換算和找出超過攝氏38度的程式------------------%
F=[98 100 102 104 98.4 98.2 98.5 101 102 99.5]; % Fahrenheit %
question_1_Centigrade=(F-32)*5/9 % Fahrenheit to Centigrade %
question_1_D=(question_1_Centigrade > 38) % 找出大於38度的denote "1"and "0" for the normal %
%-----------------------------------------------------------------%


%-------------------------第二題-----------------------------------%
%-----------------這是個matrices的判斷式----------------------------- %
A=[-10 8 6 4 -5 20];
B=[2 8 5 10 -6 3];
question_2_D_1=(A>B) % 找出A>B %
question_2_D_2=(A>5) % 找出A>5 %
question_2_D_3=(A+B) % A+B %
%------------------------------------------------------------------%


%----------------------------第三題--------------------------------%
%--------------------------這是個矩陣運算的程式------------------------ %
x=[10 20 30];
y=[1 4 6];
question_3_a=3*x+y
question_3_b=5*y./x
uestion_3_b1=5*y/x
question_3_c=4*x*2.*y
question_3_d=sind(x).*cosd(y)
question_3_e=5*x.*sind(2*y)

%在這一題要注意的是點的應用;而B=5y/x這一個題目很特別,因為有"有點b=5*y./x"和"沒點b1=5*y/x"的答案會有差異%
%------------------------------------------------------------------------%


%-----------------------------第四題--------------------------------------%
%----------------------------這是個電阻串並聯的換算------------------------%
R=[10 30 200 400]; %四種電阻%
R1=sum(R) %電阻串聯為全部的電阻值相加%
R2=1/(sum(1./R)) %利用並聯電阻公式1/R = 1/R1 + 1/R2求出並聯時的電阻值%
%------------------------------------------------------------------------%


%-------------------------第五題----------------------------------------%
%-----------------------------這是個矩陣重新排列的程式-------------------%
a=1:24;
question_5_b=reshape(a,3,8) %重新組成的 3x8 矩陣%
question_5_c=reshape(a,6,4) %重新組成的 6x4 矩陣%
question_5_d=reshape(a,2,12) %重新組成的 2x12 矩陣%
%------------------------------------------------------------------------%

執行結果
question_1_Centigrade =
36.6667 37.7778 38.8889 40.0000 36.8889 36.7778 36.9444 38.3333 38.8889 37.5000

question_1_D = 0 0 1 1 0 0 0 1 1 0

question_2_D_1 = 0 0 1 0 1 1
question_2_D_2 = 0 1 1 0 0 1
question_2_D_3 = -8 16 11 14 -11 23

question_3_a = 31 64 96
question_3_b = 0.5000 1.0000 1.0000
question_3_b1 = 0.9643
question_3_c = 80 640 1440
question_3_d = 0.1736 0.3412 0.4973
question_3_e = 1.7450 13.9173 31.1868

question_4_R1 = 640
question_4_R2 = 7.1006


question_5_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

question_5_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

question_5_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

沒有留言: