필터 지우기
필터 지우기

fsolve and indexing

조회 수: 2 (최근 30일)
Aimee Flores
Aimee Flores 2012년 5월 21일
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?

답변 (2개)

Walter Roberson
Walter Roberson 2012년 5월 21일
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.)
  댓글 수: 1
Aimee Flores
Aimee Flores 2012년 5월 21일
I'm not sure what you mean. Am I supposed to define some variable, let's call it 'a', which is some sort of expression so that my problematic line of code will be C(i,j,k,a) = fsolve(stuff) ? What is this expression I'm looking for? Is it a hypothetical output to the equations if no solution is found?

댓글을 달려면 로그인하십시오.


Sargondjani
Sargondjani 2012년 5월 21일
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)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by