Where is the recursion?
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Image Analyst
2019-3-3
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 个评论
更多回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Ordinary Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!