Info

この質問は閉じられています。 編集または回答するには再度開いてください。

I want to have a sequence of vectors using the following loop. but when i run the mat lab it will say "Subscripted assignment dimension mismatch." what can i do to index vectors and matrix.

1 回表示 (過去 30 日間)
Dinoma Degefa
Dinoma Degefa 2018 年 8 月 31 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
for k=1:100;
x(1)=[1 4 6];
A=[1 3 -1; 2 1 5; 9 7 4];
x(k+1)=A*x(k)
end
  3 件のコメント
Dinoma Degefa
Dinoma Degefa 2018 年 8 月 31 日
編集済み: Dinoma Degefa 2018 年 8 月 31 日
it gives me 100 vectors as k runs from 1 to 100. it is a loop of generating vectors as you can see from the cod. Initial vector x(1) is given and a fixed matrix A. New vector x(k+1) is generated as matrix A multiplied by a vector x(k).
Dinoma Degefa
Dinoma Degefa 2018 年 8 月 31 日
note that a vector is in R3 (3-dimensional space) and the matrix A is 3x3 matrix.

回答 (1 件)

Dennis
Dennis 2018 年 8 月 31 日
There are a few errors in your code:
  1. You try to assign 3 values [1 4 6] to only one field in x. This will not work unless x is a cell or structure.
  2. You try to multiply a 3x3 matrix with a 1x3 matrix, i think there is no mathematical correct way to do this. I am not sure which vector is supposed to be in a 3D space.
  3. This is no error, but if A and x(1) never change there is no need to reassign them in every loop iteration.
I fixed the "Subscripted assignment dimension mismatch" for you. I also swapped A*x{k} to x{k}*A, but this might not be what you want to calculate.
x=cell(101,1);
A=[1 3 -1; 2 1 5; 9 7 4];
x{1}=[1 4 6];
for k=1:100
x{k+1}=x{k}*A;
end
  1 件のコメント
Dinoma Degefa
Dinoma Degefa 2018 年 8 月 31 日
Sorry, it should be [1;4;6]. Your answer helped me a lot. Indexing is my problem. Matlab is not acceptable when indexing the vector like x(k). Now indexing it by x{k} is ok. thanks a lot.

この質問は閉じられています。

タグ

タグが未入力です。

製品

Community Treasure Hunt

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

Start Hunting!

Translated by