Where is the recursion?
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I am getting an infinite loop and running out of memory here. Please help find the recursion. I have not used matlab in a while. Thanks!
format
compact
clc
clear all
close all
%%%%%%%%%%%%%%%%%%%%%%
%%% problem 1
% values of k the system would undergo oscillations. (*Hint: Complex
% eigenvalues lead to oscillatory solutions.) 3. Simulate the system in
% MATLAB using ode45, and plot the phase portrait rdot vs.r.
r0 = 1 % m,
rdot0 = 0 % m/s,
m = 1 % kg,
wt = 1 % rad/s, and
k = 2 % N/m.
dt=.01
t=0:dt:10
% % rdot= ( 0 1 )
% % ydot= ( (k-m*w^2)/m 0)
[t,y] = ode45(@rot,[0 10],[2; 0]);
% Plot the solutions for and against t.
plot(t,y(:,1),'-o',t,y(:,2),'-o')
title('Solution of van der Pol Equation (\mu = 1) with ODE45');
xlabel('Time t');
ylabel('Solution y');
legend('y_1','y_2')
function dydt = rot(t,y)
%VDP1 Evaluate the van der Pol ODEs for mu = 1
% See also ODE113, ODE23, ODE45.
dydt = [y(1); (1-y(1)^2)*y(2)-y(1)];
[t,y] = ode45(@rot,[0 10],[2; 0]);
end
0 Commenti
Risposta accettata
Image Analyst
il 3 Mar 2019
Your main program calls ode45 which calls rot, then rot ALSO calls ODE45 which will call rot. So in essence rot is calling itself. That is recursion.
0 Commenti
Più risposte (1)
Vedere anche
Categorie
Scopri di più su Ordinary Differential Equations in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!