Help with ODE45
1 view (last 30 days)
Show older comments
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]);
0 Comments
Accepted Answer
James Tursa
on 25 Mar 2020
Edited: James Tursa
on 26 Mar 2020
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 Comments
More Answers (0)
See Also
Categories
Find more on Ordinary Differential Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!