Problem too many input arguments

1 view (last 30 days)
Ebba
Ebba on 4 Dec 2014
Answered: Torsten on 4 Dec 2014
Hi! We are having problems with ode45 this is our code:
xstart=xp; %start koordinaten i x-led
ystart=yp; %start koordinaten i y-led
xprimstart=xpprim;% Stoftsvansens starthastighet i x-led
yprimstart = ypprim;% Stoftsvansens starthastighet i y-led
tstart=0;
C=-1;
Clista = [C];
Xlista = [xstart];
Ylista =[ystart];
n=0; %vi tänker oss att vi beräknar kurvan för ca 30 partiklar
while n<20
tslut = 2989;
[t,U] = ode45(@(t,U) ekvationssystem_ode(t,U,C),[0 tslut],[xstart ystart xprimstart yprimstart]');
x = U(:, 1); % tar ut varje x-koordinat från U
y = U(:, 2);% tar ut varje y-koordinat från U
C = C+0.1;
Clista = [Clista,C]; %Lägger till varje nytt C värde i listan för C
Xlista = [Xlista,x]; %Lägger till varje nytt x värde i listan för X
Ylista = [Ylista,y]; %Lägger till varje nytt y värde i listan för Y
n=n+1;
end
This is our funktion we us in ode45
function uprim =ekvationssystem_ode(t,U,C) %funktion som löser vårt ekvationssystem
s=(U(1)^2 + U(2)^2)^0.5; %definition för s givet i uppgiften uprim =[U(3),U(4),(-C*U(1))/(s^3),(-C*U(2))/(s^3)]'; %vektorn uprim som ODE45 använder för att returnera vektorn U
these are our errors. ...
Error using ekvationssystem_ode Too many input arguments.
Error in @(t,U)ekvationssystem_ode(t,U,C)
Error in odearguments (line 87) f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 113) [neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn, ...
Error in mainprogram (line 68) [t,U] = ode45(@(t,U) ekvationssystem_ode(t,U,C),[0 tslut],[xstart ystart xprimstart yprimstart]');
Please help us! :)
  1 Comment
Adam
Adam on 4 Dec 2014
Have you tried isolating the problem and calling
@(t,U) ekvationssystem_ode(t,U,C)
with arguments:
[0 tslut]
and
[xstart ystart xprimstart yprimstart]'
outside of the ode45 function?
I can't see anything obviously wrong glancing at the code. I have never used ode45 so don't know anything about that, but it looks as though the error is independent of the use of the ode45 function and caused by your function handle passed to that.

Sign in to comment.

Answers (1)

Torsten
Torsten on 4 Dec 2014
Maybe you have to replace
[t,U] = ode45(@(t,U) ekvationssystem_ode(t,U,C),[0 tslut],[xstart ystart xprimstart yprimstart]');
by
[t,U] = ode45(@(t,y) ekvationssystem_ode(t,y,C),[0 tslut],[xstart ystart xprimstart yprimstart]);
and
uprim =[U(3),U(4),(-C*U(1))/(s^3),(-C*U(2))/(s^3)]';
by
uprim =[U(3);U(4);(-C*U(1))/(s^3);(-C*U(2))/(s^3)];
?
Best wishes
Torsten.

Community Treasure Hunt

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

Start Hunting!