我必須使用for循環乘以D=[cos(pi/18) -sin(pi/18); sin(pi/18) cos(pi/18)]
乘以X= [0.80;0]
9次。我想將結果存儲在表格中:X=zeros(2,10)
matlab中的矩陣乘法,使用for循環
我有點失落。
Anders。
我必須使用for循環乘以D=[cos(pi/18) -sin(pi/18); sin(pi/18) cos(pi/18)]
乘以X= [0.80;0]
9次。我想將結果存儲在表格中:X=zeros(2,10)
matlab中的矩陣乘法,使用for循環
我有點失落。
Anders。
你的問題不是很清楚。循環D*X
(2x1矩陣)次不給你2x10矩陣。
這是你在找什麼?
D = [cos(pi/18) -sin(pi/18); sin(pi/18) cos(pi/18)];
X = [0.80;0];
O = ones(1,9);
A = D*X*O
輸出:
A =
Columns 1 through 8:
0.78785 0.78785 0.78785 0.78785 0.78785 0.78785 0.78785 0.78785
0.13892 0.13892 0.13892 0.13892 0.13892 0.13892 0.13892 0.13892
Column 9:
0.78785
0.13892
注意:矩陣操作不需要在Matlab中環時代最
IF @ jkshah的回答的結果是你想要的,使用他的答案(也許將O
矩陣更改爲O = ones(1,10)
)。 MatLab這樣命名的原因是因爲它(或她:p)在矩陣操作方面非常出色,並且您可以更好地避免循環。如果你想使用循環,這是一種方法:
D = [cos(pi/18) -sin(pi/18); sin(pi/18) cos(pi/18)]; % Input
X = [0.80;0]; % Input
A = D*X; % The function
X = zeros(2,10); % Initialize the result table
X(:,1)=A; % Insert the result in
% the first column
for i =1:9 % Iterate to fill the 2X10 table
X(:,i+1) = A;
end
所以,你想乘以一個2×2矩陣9次2x2矩陣,並得到一個2x10輸出。你需要更具體,而不是有意義的幫助。 – learnvst