Multiplying 2 matrices, using a for loop and storing results in a table.
Ältere Kommentare anzeigen
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 Kommentare
Azzi Abdelmalek
am 26 Okt. 2013
Can you explain what means 9 times?
Anders
am 27 Okt. 2013
Anders
am 27 Okt. 2013
Akzeptierte Antwort
Weitere Antworten (1)
sixwwwwww
am 27 Okt. 2013
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!
1 Kommentar
Anders
am 28 Okt. 2013
Kategorien
Mehr zu Update figure-Based Apps finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!