9/29/2006

PROBLEM #2 黃世榮

%problem#2
程式流程:

%question 1
clear
format short
B=[98 100 102 104 98.4 98.2 98.5 101 102 99.5]
C=(B-32)*5/9 % that's a)'s answer
[u,v]=find(C>38);
D=zeros(1,10);
D(u,v)=1

%question 2
clear
A= [10 8 6 4 -5 20]
B=[2 8 5 10 -6 3]
D1=[A>B]
D2=(A>5)
D3=A+B

%question 3
clear
x=[10 20 30]
y=[1 4 6]
A=3*x+y
B=5*y/x
C=4*x.*y*2
D=sin(x).*cos(y)
E=5*x.*sin(2*y)

%question 4
R=[ 10 30 200 400]
Req1=sum(R)
%series
Req2=prod(R)/sum(R)
%parallel


%question 5
A=[1:1:24]
B=reshape(A,3,8)
C=reshape(A,6,4)
D=reshape(A,2,12)

執行結果:

Q1:

B =

Columns 1 through 8

98.0000 100.0000 102.0000 104.0000 98.4000 98.2000 98.5000 101.0000

Columns 9 through 10

102.0000 99.5000


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 =

0 0 1 1 0 0 0 1 1 0

Q2:

A =

10 8 6 4 -5 20


B =

2 8 5 10 -6 3


D1 =

1 0 1 0 1 1


D2 =

1 1 1 0 0 1


D3 =

12 16 11 14 -11 23

Q3:

x =

10 20 30


y =

1 4 6


A =

31 64 96


B =

0.9643


C =

80 640 1440


D =

-0.2939 -0.5967 -0.9487


E =

45.4649 98.9358 -80.4859

Q4:

R =

10 30 200 400


Req1 =

640


Req2 =

37500

Q5:

A =

Columns 1 through 13

1 2 3 4 5 6 7 8 9 10 11 12 13

Columns 14 through 24

14 15 16 17 18 19 20 21 22 23 24


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 =

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 =

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

討論:實際上在比較龐大的矩陣,用到很多元素指令,也許可用指令配合迴圈比較清楚

沒有留言: