Maximum recursion limit of 500 reached.
Mostrar comentarios más antiguos
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')
Respuestas (1)
Cris LaPierre
el 18 de Mzo. de 2021
Editada: Cris LaPierre
el 18 de Mzo. de 2021
0 votos
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 comentarios
Anna Taylor
el 18 de Mzo. de 2021
Cris LaPierre
el 18 de Mzo. de 2021
Editada: Cris LaPierre
el 18 de Mzo. de 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
Categorías
Más información sobre Programming en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
