Where is the recursion?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
ddd ppp
am 3 Mär. 2019
Beantwortet: ddd ppp
am 3 Mär. 2019
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 Kommentare
Akzeptierte Antwort
Image Analyst
am 3 Mär. 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 Kommentare
Weitere Antworten (1)
Siehe auch
Kategorien
Mehr zu Ordinary Differential Equations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!