How can i use symbolic equations in ode45

27 ビュー (過去 30 日間)
Volkan Yangin
Volkan Yangin 2020 年 11 月 9 日
コメント済み: Ameer Hamza 2020 年 11 月 9 日
In my code, i tried to convert my symbolic function to numeric to solve it via ode45, but took this error message:
Error using odearguments (line 113)
Inputs must be floats, namely single or double.
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in Untitled8 (line 8)
[t,x1_dot_sol] = ode45(x1_dot_num,tspan,x1_0);
Is there any way to fix it?
Thx,
clear all
clc
syms x1
x1_dot=(6*atan((53*x1)/9))/(25*pi) - 40*x1 + (6*atan((179*x1)/18))/(25*pi), (6*atan((53*x1)/9))/(25*pi) - 40*x1 + (6*atan((179*x1)/18))/(25*pi), (6*atan((53*x1)/9))/(25*pi) - 40*x1 + (6*atan((179*x1)/18))/(25*pi)
x1_dot_num = @(t,x1) matlabFunction(x1_dot);
x1_0 = 4;
tspan = [0 3];
[t,x1_dot_sol] = ode45(x1_dot_num,tspan,x1_0);

採用された回答

Ameer Hamza
Ameer Hamza 2020 年 11 月 9 日
編集済み: Ameer Hamza 2020 年 11 月 9 日
This is the correct way to write this code
% clear all
clc
syms x1
x1_dot = (6*atan((53*x1)/9))/(25*pi) - 40*x1 + (6*atan((179*x1)/18))/(25*pi)
x1_dot_num = matlabFunction(x1_dot, 'Vars', {'t', 'x1'});
x1_0 = 4;
tspan = [0 3];
[t,x1_dot_sol] = ode45(x1_dot_num,tspan,x1_0);
plot(t, x1_dot_sol)
Also, for your ODE, you don't need symbolic toolbox, Following code is also correct
clc
x1_dot_num = @(t, x1) (6*atan((53*x1)/9))/(25*pi) - 40*x1 + (6*atan((179*x1)/18))/(25*pi);
x1_0 = 4;
tspan = [0 3];
[t,x1_dot_sol] = ode45(x1_dot_num,tspan,x1_0);
plot(t, x1_dot_sol)
  2 件のコメント
Volkan Yangin
Volkan Yangin 2020 年 11 月 9 日
Now, i am trying to adapt your approach for my problem with for loop. Thanks a lot!
Ameer Hamza
Ameer Hamza 2020 年 11 月 9 日
I am glad to be of help!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSymbolic Math Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by