Unable to store matrix array in for loop
Mostra commenti meno recenti
t = linspace(10^-4,10^12,17)
for i = 1:17
m = inv((At * Cd * A) + (t(i) * Ht * H)) * At * Cd * do
end
Solution for m is a 20 by 1 matrix
but im having issues storing each iteration of the solution as an individual set (i.e m1 , m2, m3 ....m17)
it just lumps all the solutions as m
making it unable for me to call out a solution of choice
3 Commenti
I suspect that you actually want to generate logarithmically spaced t values:
>> t = logspace(-4,12,17)
t =
0.0001 0.001 0.01 0.1 1 10 100 1000 10000 1e+005 1e+006 1e+007 1e+008 1e+009 1e+010 1e+011 1e+012
Compared to the rather strange linearly spaced values that you have now:
>> t = linspace(1e-4,1e12,17)
t =
0.0001 6.25e+010 1.25e+011 1.875e+011 2.5e+011 3.125e+011 3.75e+011 4.375e+011 5e+011 5.625e+011 6.25e+011 6.875e+011 7.5e+011 8.125e+011 8.75e+011 9.375e+011 1e+012
Prince Igweze
il 5 Nov 2019
Prince Igweze
il 5 Nov 2019
Risposte (2)
Bhaskar R
il 5 Nov 2019
t = linspace(10^-4,10^12,17);
m = zeros(length(t),1); % initialize with zeros
for i = 1:17
m(i) = inv((At * Cd * A) + (t(i) * Ht * H)) * At * Cd * do; % store values for each iteration
end
1 Commento
Prince Igweze
il 5 Nov 2019
randerss simil
il 13 Feb 2021
t = linspace(10^-4,10^12,17)
for i = 1:17
m{i} = inv((At * Cd * A) + (t(i) * Ht * H)) * At * Cd * do ; % use cell array
end
Use cell array as above
Categorie
Scopri di più su Creating and Concatenating Matrices in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!