Info

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

Storing values in a loop

4 ビュー (過去 30 日間)
Prince Igweze
Prince Igweze 2019 年 11 月 7 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
t = linspace(10^-4,10^12,17)
q = zeros(length(t),1);
for i = 1:17
m(i) = inv((At * Cd * A) + (t(i) * Ht * H)) * At * Cd * do
end
how can i store the values in this loop
m is a 50 by 1 matrix
Note that all the variable in the equation are also matrixes
Shows this when i try running it
Unable to perform assignment because the left and right sides have a different number of elements.
  2 件のコメント
Shubham Gupta
Shubham Gupta 2019 年 11 月 7 日
編集済み: Shubham Gupta 2019 年 11 月 7 日
Note that all the variable in the equation are also matrixes
What is the dimension for the right side matrix? I am guessing it is not (1x1) dimensional matrix otherwise it would have worked, since left side is of 1x1 dimesion.
But you can use cell type array to do this kind of assignment:
t = linspace(10^-4,10^12,17);
q = zeros(length(t),1);
m{1,17} = {}; % predefine cell vector m of dimesion 1x17
for i = 1:17
m{i} = inv((At * Cd * A) + (t(i) * Ht * H)) * At * Cd * do; % note m{i} is used instead of usual m(i)
end
Let me know if you have doubts !
Stephen23
Stephen23 2019 年 11 月 7 日
編集済み: Stephen23 2019 年 11 月 7 日
To make your code more efficient and robust you should probably be using mldivide instead of inv and *. Explicit matrix inversion is rarely required (because there are better methods for solving such systems of equations).

回答 (0 件)

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by