Help with ODE45

1 回表示 (過去 30 日間)
Sydney Brown
Sydney Brown 2020 年 3 月 25 日
編集済み: James Tursa 2020 年 3 月 26 日
So I need to solve the second order differential function y''-y=G(t) where G(t) is the two functions seen below. I attempted to try to use ode45 to solve the first, but it didn't work. I also need to plot these two solutions together.
syms k t
G1 = symsum(t-2*k*pi,k,0,3);
G2 = symsum(2*pi-t+2*k*pi,k,3,5);
[tsol1,xsol1] = ode45(@(t,x) [x(2);G1-x(1)], [0,3],[0; 1]);

採用された回答

James Tursa
James Tursa 2020 年 3 月 25 日
編集済み: James Tursa 2020 年 3 月 26 日
G1 and G2 are symbolic expressions. ode45( ) is a numeric solver. You will need to turn G1 and G2 into actual non-symbolic code in order to use them with ode45( ). I.e., non-symbolic functions or expressions involving t. E.g., could create a function handle for this:
>> F1 = str2func(['@(t)' char(G1)])
F1 =
@(t)4*t-12*pi
>> [tsol1,xsol1] = ode45(@(t,x) [x(2);F1(t)-x(1)], [0,3],[0; 1]);

その他の回答 (0 件)

カテゴリ

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