Where is the recursion?

2 ビュー (過去 30 日間)
ddd ppp
ddd ppp 2019 年 3 月 3 日
回答済み: ddd ppp 2019 年 3 月 3 日
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

採用された回答

Image Analyst
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.

その他の回答 (1 件)

ddd ppp
ddd ppp 2019 年 3 月 3 日
thanks

カテゴリ

Help Center および File ExchangeOrdinary Differential Equations についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by