too many input arguments error
1 次查看(过去 30 天)
显示 更早的评论
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 个)
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 个评论
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 Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!