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 Kommentar

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.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Torsten
Torsten am 4 Dez. 2014

0 Stimmen

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.

Kategorien

Mehr zu Programming finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 4 Dez. 2014

Beantwortet:

am 4 Dez. 2014

Community Treasure Hunt

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

Start Hunting!

Translated by