Maximum recursion limit of 500 reached.
Afficher commentaires plus anciens
I am trying to plot with this code below but keep getting a Maximum recursion limit of 500 reached error.
function yp = nonlinear (t,y)
e = .2;
yp(1) = y(2);
yp(2) = (-y(1)-e*y(1)^3);
tspan = [0 20];
y0 = [0;0];
[t,y] = ode45('nonlinear', tspan, y0);
plot (t,y(:,1))
grid
xlabel ('time')
ylabel ('u')
title ('u vs t')
Réponses (1)
Cris LaPierre
le 18 Mar 2021
Modifié(e) : Cris LaPierre
le 18 Mar 2021
0 votes
You have given your plotting function and your odefunc the same name. This is causing ode45 to call your function recursively (call itself).
Change the name of either give your odefunc or you plotting function.
2 commentaires
Anna Taylor
le 18 Mar 2021
Cris LaPierre
le 18 Mar 2021
Modifié(e) : Cris LaPierre
le 18 Mar 2021
I've never used MATLAB before so I'm just lost in what I'm doing.
I suggest going through MATLAB Onramp. It doesn't cover odes, but it will at least give you the basics, which you will need for a foundation to build on.
Now the error is that you have not defined an ode to solve, at least not the way MATLAB is expecting. See this example on the ode45 documentation page.
I think you want something like this.
tspan = [0 20];
y0 = [0;0];
[t,y] = ode45(@non, tspan, y0);
plot (t,y(:,1))
grid
xlabel ('time')
ylabel ('u')
title ('u vs t')
function yp = non(t,y)
yp = zeros(2,1);
e = .2;
yp(1) = y(2);
yp(2) = (-y(1)-e*y(1)^3);
end
Catégories
En savoir plus sur Programming dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
