fsolve and indexing
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I'm having a hard time trying to index my outputs into a vector because I wish to plot it. Here is my program:
R = 8.314;
for i = 1:4
MR(i) = i;
C_MeOH0(MR) = 1./(1 + MR);
C_MH0(MR) = MR./(1 + MR);
for j = 353:10:383
T(j) = j;
k1(j) = (6.74.*10.^8.*exp(-90000./(R.*j))).*3600;
k2(j) = (1.25.*10.^10.*exp(-105900./(R.*j))).*3600;
for k = 1:20
tau(k) = k;
F = @(C)[(1./(1 + i)) - C(1) - (k1.*C(1).*C(2).*k) - (2.*k2.*(C(1).^2).*C(2).*k); ((i./(1 + i)) - C(2) - (k1.*C(1).*C(2).*k) - (k2.*(C(1).^2).*C(2).*k))];
C0 = [1; 1];
C = fsolve(F, C0);
end
end
end
However when I try to index my C as C(i,j,k) I get this error:
??? Assignment has more non-singleton rhs dimensions than non-singleton subscripts
Error in ==> try2 at 25 C(i,j,k) = fsolve(F, C0);
Can anyone please help me?
0 Commenti
Risposte (2)
Walter Roberson
il 21 Mag 2012
fsolve() is returning multiple values. Which makes perfect sense considering that you have asked it to find the solution to a two-dimensional problem, so you expect to get back one value for each of the dimensions. You will want to write the output to an array with one more dimension than you have now.
(I recommend that you test to figure out what output you get if no solution is found.)
Sargondjani
il 21 Mag 2012
i think you want to use cell arrays to store the vectors of the solutions:
C{i,j}=fsolve(....)
to call the content: C{i,j} will give you a 2 element vector you can regard this as a normal vector. to get the second element in the vector: C{i,j}(2)
0 Commenti
Vedere anche
Categorie
Scopri di più su Loops and Conditional Statements in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!