MATLAB Answers

Too many input arguments, which arguments should I remove?

Hi all, on the attached code, I am trying to use a for-loop and ode45 to solve odes and an algebraic equation in 31 iterations. However, I get an error message
Error using my_odesloop>odes
Too many input arguments.
Error in my_odesloop>@(t,y)odes(t,y,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z) (line 46)
sol(j) = ode45(@(t,y) odes(t,y,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z),t,y0);
Error in odearguments (line 90)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in my_odesloop (line 46)
sol(j) = ode45(@(t,y) odes(t,y,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z),t,y0);
I don't know which arguments to remove.
Please help.

  댓글 수: 2

YOur code is very buggy.......need lot's of changes.....what you are trying actually?
Thanks a lot for the response KSSV. I am trying to use a for-loop and ode45 to solve odes and an algebraic equation. The odes are in lines 60 to 82. The algebraic equation is nested in lines 49 to 51.

로그인 to comment.

답변 수: 1

Walter Roberson 님의 답변 24 Oct 2018
 채택된 답변

Your function line for odes needs to list A, B, C, and so on.

  댓글 수: 3

Thanks a lot Walter, it resolved the error of "too many input argument". However, the code now requires me to define x. Is it correct to nest the odes function inside the my_odesloop function?
Adopt the example "ODE with Time-Dependent Terms" under
https://de.mathworks.com/help/matlab/ref/ode45.html
to your case.
Best wishes
Torsten.
Guessing:
x0 = 9.46e-1;
xin = x0;
for j = 1:length(t)
sol(j) = ode45(@(t,y) odes(t,y,xin,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z),t,y0);
for i = 1:length(t)
x(i) = fsolve(@(x) x + 2.* e(j) - ((c(j).* A.*x)/(x.^2 + A.*x + A*B))- 2.*((c(j).*A*B)/(x.^2 ...
+ A.*x + A*B))-((d(j).*M.*x)/(x.^2 + M.*x + M*N))- 2.*((d(j).*M.*N)/(x.^2 ...
+ M.*x + M*N))- Y./x, x0);
end
plot(t,sol)
xin = x(j); %complete guess
end
end
function dydt = odes(t,y,x,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z)
a = y(1);
b = y(2);
c = y(3);
d = y(4);
e = y(5);
f = y(6);
g = y(7);
dydt = zeros(7,1);
dydt(1) = (1 /J).* (K.* L - K.* a ) - ((a.* E.* F - G.* ((c.* (x).^2)/((x).^2 + A.* (x) + A.* B))) / ( (1/H) + G/ ((1 + C.* e / (D.* c)).* I)));
dydt(2) = (1 /J).* (K .* R - K .* b) - (P .* (1 + C * e / (O .* d)) .* (b .* E .* F / Q - ((d.* (x(i)).^2)/((x).^2 + M.* (x) + M.* N))));
dydt(3) = ((a.* E.* F - G.* ((c.* (x).^2)/((x).^2 + A.* (x) + A.* B))) / ( (1/H) + G/ ((1 + C.* e / (D.* c)).* I))) - (Z .* 1.62e-3 .* exp(-5152 / F) .* ( (e .* ((c.* A .* B)/((x).^2 + A .* (x) + A .* B)) / S) - 1).^3 / T);
dydt(4) = (- U .* V .* W .* f .* (x) .* (1 - (X .* (x))/(1+ X .* (x)))) - (P .* (1 + C * e / (O .* d)) .* (b .* E .* F / Q - ((d.* (x).^2)/((x).^2 + M.* (x) + M.* N))));
dydt(5) = (- U .* V .* W .* f .* (x) .* (1 - (X .* (x))/(1+ X .* (x)))) - (Z .* 1.62e-3 .* exp(-5152 / F) .* ( (e .* ((c.* A .* B)/((x).^2 + A .* (x) + A .* B)) / S) - 1).^3 / T);
dydt(6) = (- U .* V .* W .* f .* (x) .* (1 - (X .* (x))/(1+ X .* (x))));
dydt(7) = (Z .* 1.62e-3 .* exp(-5152 / F) .* ( (e .* ((c.* A .* B)/((x).^2 + A .* (x) + A .* B)) / S) - 1).^3 / T);
dydt = [dydt(1),dydt(2),dydt(3),dydt(4),dydt(5),dydt(6),dydt(7)];
end

로그인 to comment.



Translated by