Problem with returning to Main function from subfunction
이전 댓글 표시
Hi everybody,
I'm running into a problem when I want to execute a code that is schematic like the following (See below). It is supposed to produce the orbital decay of space objects. I use a ODE integrator like Runge-Kutte Fehleberg to get the rates of change. When a certain value is reached (like altitude is 0) I want to abort the integration and return the values to the main function for plotting etc. The integration and orbit decay seems to work ok but when the abort criteria is reached I get the following error:
-------------------------------------------------------------------
_Error in SimpleDecay>rates (line 135) dfdt = zeros(7,1);
Output argument "dydt" (and maybe others) not assigned during call to "C:\Users\...\SimpleDecay.m>SimpleDecay/rates".
Error in rkf45 (line 79) f(:,i) = feval(ode_function, t_inner, y_inner);
Error in SimpleDecay (line 86) [t,f] = rkf45(@rates, tspan, f0);
_--------------------------------------------------------------
I'm not sure whether I placed the abort 'if' correctly or what the problem really is so every help is highly appreciated!
Thanks in advance, David
The code is schematic like this:
function main
%Some definitions etc.
%Define timespan of integration & initial value vector
% Calling the integrator
[t,f] = rkf45(@rates, tspan, f0);
%return the solutions
a = f(:,1);
%etc.
plotting %as a subfunction call
return
function dydt = rates(ti,y)
dfdt = zeros(7,1);
initial vector definition
a = y(1);
%etc.
% Define some needed values
% Return when value is reached
if a < Re
return
end
%Calculate rates
dadt = ...
% etc.
% Load derivatives into output vector
dydt(1) = dadt;
end % end rates
end % end main
댓글 수: 2
Andrew Newell
2012년 1월 11일
This ODE solver is from MATLAB Central. Have you tried contacting the author? Also, have you considered using the MATLAB solvers like ode45?
David
2012년 1월 11일
채택된 답변
추가 답변 (2개)
카테고리
도움말 센터 및 File Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!