too many input arguments error

조회 수: 1 (최근 30일)
Anna Dorfi
Anna Dorfi 2013년 3월 6일
I keep getting this error but I do not see what is wrong. I need to plot concentrations of species a through g over a time tau
This is my code:
c0 = [2 2 0 0 0 0 0]; %feed concentrations
v = [-2 -1 1 1 0 0 0;
0 0 -2 0 1 1 0;
0 -1 0 0 0 -1 1]; %stoichiometric matrix
k = [0.100 0.05 0.037 2.5 .6]; %rate constants
options = []; %options use by fsolve
% loop over tau2's
for tau2vec=[0:0.5:30];
[c2,fval,exitflag] = fsolve(@mysolv,c0,options);
if exitflag<=0, warning('fsolve did not converge'),end
end
plot(tau2vec,ca2,'-r',tau2vec,cb2,'-b', tau2vec,cc2,'.-g',tau2vec,cd2,'-',tau2vec,ce2,'oy',tau2vec,cf2,'-',tau2vec,cg2,'+b');
xlabel('time (min)')
legend('c_A','c_B','c_C','c_D','c_E','c_F','c_G',0)
ylabel('concentration (M)')
title('Concentration Profiles Part B')
% function definition, fsolve will iterate on c2 until mysolv(c2) is zero
function y = mysolv(c2)
ca2 = c2(1);
cb2 = c2(2);
cc2 = c2(3);
cd2 = c2(4);
ce2 = c2(5);
cf2 = c2(6);
cg2 = c2(7);
r2 = [k(1)*ca2^2*cb2 - k(2)*cc2*cd2;
k(3)*cc2^2;
k(4)*cb2*cf2-k(5)*cg2];
R2 = v'*r2;
y = c0 - c2 + R2*tau2vec; % tau2 and c0 are defined outside the function
end
end
  댓글 수: 1
Walter Roberson
Walter Roberson 2013년 3월 6일
Which line is reporting too many input arguments?

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

답변 (1개)

Brian B
Brian B 2013년 3월 6일
Where do you define ca2, cb2, ...? Do you need to get those from the value of c2 at each iteration of your loop?
  댓글 수: 2
Anna Dorfi
Anna Dorfi 2013년 3월 6일
Yes. I need to output each species concentration from the c2 value that is being solved. The initial species concentrations are in the c0 vector.
Brian B
Brian B 2013년 3월 6일
Currently you're overwriting the value of c2 at every iteration. You should do something like
TAU2VEC = [0:0.5:30];
C2 = zeros(length(c0), length(TAU2VEC)
for k=1:length(TAU2VEC)
tau2vec =TAU2VEC(k);
[c2,fval,exitflag] = fsolve(@mysolv,c0,options);
if exitflag<=0, warning('fsolve did not converge'),end
C2(:,k) = c2;
end
Then you'll plot with C2 and TAU2VEC.

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

카테고리

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