Naman Shah
Naman Shah

Reputation: 47

Setting Up ODE45 Function

This might be a trivial question, but I need help setting up the following ODE to be solved with ODE45:

4x" + 32x' + 60x = 3f'(t) + 2f(t), with initial conditions x(0) = 0, x'(0) = 0, and f(t) = 5t, from t = 0 to t = 1.5

Making substitutions, I end up with the following:

4x" + 32x' + 60x = 15 + 10t,
x" = -8x' -15x +15/4 + 2.5t

And setting up the vector:

x(1)' = x(2)
x(2)' = -8x(1) -15x + 15/4 + 2.5t

[t,x] = ode45(@(t,x) [x(2); -8.*x(1) - 15.*x + 15./4 + 2.5.*t],[0 1.5],[0 0]);

I get the following error:

Error using odearguments (line 92)
@(T,Y)[Y(2);-8.*Y(1)-15.*Y+15./4+2.5.*T] returns a vector of length 3, but the length of initial conditions vector is 2.
The vector returned by @(T,Y)[Y(2);-8.*Y(1)-15.*Y+15./4+2.5.*T] and the initial conditions vector must have the same number of elements.

Have I set the ODE expression up wrongly, or am I missing an initial condition?

Upvotes: 0

Views: 87

Answers (1)

Naman Shah
Naman Shah

Reputation: 47

Whoops solved it.

I didn't realize that x(2) corresponded to x', and x(1) corresponded to x. Making the necessary substitutions fixed it.

Upvotes: 2

Related Questions