필터 지우기
필터 지우기

Multiplying 2 matrices, using a for loop and storing results in a table.

조회 수: 3 (최근 30일)
Anders
Anders 2013년 10월 26일
댓글: Anders 2013년 10월 28일
Hey.
I have to multiply D=[cos(pi/18) -sin(pi/18); sin(pi/18) cos(pi/18)] by X= [0.80;0] 9 times, using a for loop. I want to store the results in a table of the form: X=zeros(2,10).
I've tried to do it like this:
X=[0.80;0]
t=pi/18
D=[cos(t) -sin(t); sin(t) cos(t)]
d=D*X
X=zeros(2,10)
for D=10:2,
X(D)=d;
end
But this just writes:
X =
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
Anders. I'm a bit lost.
  댓글 수: 3
Anders
Anders 2013년 10월 27일
It means, that i have to multiply D by X 9 times. It would be the same as D^9*X. But i have to store all the results, in a table (2, 10). First: D*X, second: D*(D*X) Third: D*(D*(D*X) and so on.
Anders
Anders 2013년 10월 27일
I've tried to do it like this: X=[0.80;0] t=pi/18 D=[cos(t) -sin(t); sin(t) cos(t)] d=D*X X=zeros(2,10) for D=10:2, X(D)=d; end But this just writes: X = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

댓글을 달려면 로그인하십시오.

채택된 답변

Andrei Bobrov
Andrei Bobrov 2013년 10월 26일
편집: Andrei Bobrov 2013년 10월 27일
[EDIT]
X=[0.80;0];
t=pi/18;
D=[cos(t) -sin(t); sin(t) cos(t)];
X(2,10) = 0;
for jj = 2:size(X,2)
X(:,jj) = D*X(:,jj-1);
end
  댓글 수: 4

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

sixwwwwww
sixwwwwww 2013년 10월 27일
Dear Andres, you can do it as follows using for loop:
D = [cos(pi/18) -sin(pi/18); sin(pi/18) cos(pi/18)];
X = [0.80;0];
result = zeros(2, 9);
for i = 1:9
result(1, i) = D(1, 1) * X(1) + D(1, 2) * X(2);
result(2, i) = D(2, 1) * X(1) + D(2, 2) * X(2);
end
disp(result)
I hope it helps. Good luck!

카테고리

Help CenterFile Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by