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!

답변 (1개)

Walter Roberson
Walter Roberson 2021년 1월 21일

0 개 추천

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

댓글 수: 3

Edward
Edward 2021년 1월 21일
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 2021년 1월 21일
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 2021년 1월 21일
Okay, thank you so much for the help!

댓글을 달려면 로그인하십시오.

카테고리

태그

질문:

2021년 1월 21일

댓글:

2021년 1월 21일

Community Treasure Hunt

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

Start Hunting!

Translated by