Infinite recursion in code to graph second order differential equations
Afficher commentaires plus anciens
I am trying to implement the sample code from a section titled Pass Extra Parameters to ODE Function in an article on second order differential equations: https://www.mathworks.com/help/matlab/ref/ode45.html
When I try to execute the following code, I get an error message saying there is likely an infinite recursion in the program.
function dydt = odefcn(t,y,A,B)
A = 1;
B = 2;
tspan = [0 5];
y0 = [0 0.01];
[t,y] = ode45(@(t,y) odefcn(t,y,A,B), tspan, y0);
dydt = zeros(2,1);
dydt(1) = y(2);
dydt(2) = (A/B)*t.*y(1);
plot(t,y(:,1),'-o',t,y(:,2),'-.')
end
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Ordinary Differential Equations 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!