Error in ode45 (line 115)

I'm trying to solve a second-order ODE and am receiving the following errors:
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0,
options, varargin);
Error in code (line 17)
[out1,out2] = ode45(ode,[0 100],cond);
Here's my code:
syms phi(t) theta(t)
phid(t) = diff(phi,t);
thetad(t) = diff(theta,t);
q(t) = [phi(t);theta(t)];
qd(t) = diff(q,t);
qdd(t)= diff(qd,t);
a = 10;
b = 3;
y = 2;
d = 5;
M = [a+b*(sin(theta))^2 y*cos(theta);y*cos(theta) b];
C = [b*thetad*sin(theta)*cos(theta) -y*thetad*sin(theta)+b*phid*sin(theta);-b*phid*sin(theta) 0];
G = [0;-d*sin(theta)];
ode = 0 == M*qdd+C*qd+G;
cond = [q(0)==[1;-1], qd(0)==[0;0]];
[out1,out2] = ode45(ode,[0 100],cond);
I'm not very experienced with Matlab, so I apologize if this is an obvious mistake I'm making.
Thank you in advance!

Antworten (1)

Walter Roberson
Walter Roberson am 21 Jan. 2021

0 Stimmen

ode45 can never be used for symbolic expressions. See dsolve() instead, or see the first example for odeFunction

3 Kommentare

Edward
Edward am 21 Jan. 2021
Thanks. I was originally using dsolve but kept receiving even more errors, which I looked up and tried to resolve by using ode 45. These are the errors I get with dsolve:
Warning: Unable to find symbolic solution.
> In dsolve (line 216)
In code (line 16)
Walter Roberson
Walter Roberson am 21 Jan. 2021
That is not an error, that is a warning that dsolve does not know how to solve that system. Either dsolve does not have the algorithm for that system, or else there is no closed form solution for the system, or else the system is inconsistent for closed form.
You should follow the guidance in odeFunction first example.
Edward
Edward am 21 Jan. 2021
Okay, thank you so much for the help!

Melden Sie sich an, um zu kommentieren.

Tags

Gefragt:

am 21 Jan. 2021

Kommentiert:

am 21 Jan. 2021

Community Treasure Hunt

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

Start Hunting!

Translated by