MATLAB Answers

Why does my code think I want to use the Symbolic Math Toolbox when in reality I want to solve a system of ODEs numerically?

2 ビュー (過去 30 日間)
Augusto C
Augusto C 2019 年 12 月 10 日
Edited: Augusto C 2019 年 12 月 10 日
I'm using MATLAB 2016a. I have a function that is called from the code's driver function. The called function has a line to solve a system of ODEs using ode45:
global TIME
global TORQUE I %% TORQUE = [0 0 0]' and I = [1e-31 1e-31 1e-31]' initially.
%% The variables "spin", "axes" and "dt" below are passed from the driver function.
%%create one vector array that has the spin and axes
y = reshape([spin' axes],1,12); %% [spin' axes] is a 3 x 4 matrix
t0 = TIME - dt; %% Initially, TIME = dt = 5.1e-5
%% Compute initial slopes
yp(1) = (TORQUE(1) + y(2)*y(3)*(I(2)-I(3)))/I(1);
yp(2) = (TORQUE(2) + y(3)*y(1)*(I(3)-I(1)))/I(2);
yp(3) = (TORQUE(3) + y(1)*y(2)*(I(1)-I(2)))/I(3);
yp(4:6) = y(3)*y(7:9) - y(2)*y(10:12);
yp(7:9) = y(1)*y(10:12) - y(3)*y(4:6);
yp(10:12) = y(2)*y(4:6) - y(1)*y(7:9);
%% create function handle to euler, which contains ODEs
fun=@euler;
%% Set integration parameters
tmp={'RelTol' 'AbsTol' 'MinStep' 'MaxStep' 'NextStep' ...
'SafetyFactor' 'GrowthLimit' 'ShrinkLimit' 'FallBack'
1e-5 1e-8 .001*dt dt nan ...
0.9 5 0.1 'on'};
params=struct(tmp{:});
%% Call integrator
[t,y] = ode45(fun,[t0, t0 + dt],yp,params)
When I execute the code, it stops at the ode45 line and produces the following messages:
Screen Shot 2019-12-10 at 7.26.31 AM.png
Any insight into why this is happening would be appreciated.

  0 件のコメント

サインイン to comment.

採用された回答

Stephen Cobeldick
Stephen Cobeldick 2019 年 12 月 10 日
編集済み: Stephen Cobeldick 2019 年 12 月 10 日
Take a look at these two lines:
%% create function handle to euler, which contains ODEs
fun=@euler;
euler is in the symbolic toolbox:
Based on your comment you seemed to think that you were calling another function.

  1 件のコメント

Augusto C
Augusto C 2019 年 12 月 10 日
That was it! I hadn't realized "euler" was part of the Symbolic Toolbox. Those error messages are now gone. Thank you.

サインイン to comment.

More Answers (0)

サインイン してこの質問に回答します。


Translated by