MATLAB Answers

Help with ODE45

3 views (last 30 days)
Sydney Brown
Sydney Brown on 25 Mar 2020
Edited: James Tursa on 26 Mar 2020
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

Sign in to comment.

Accepted Answer

James Tursa
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

Sign in to comment.

More Answers (0)