필터 지우기
필터 지우기

Trying to solve and plot the non-linear pendulum equation

조회 수: 3 (최근 30일)
Alexandros
Alexandros 2017년 11월 16일
댓글: Star Strider 2017년 11월 17일
Hi! I have the d^2/dt^2 + g/L(sinθ)=0 2nd order D.E. (Simple Pendulum) which I have seperated to two 1st order D.E.
y(1) = dθ/dt = ω = u_θ , y(2) = dω/dt = -b^2*sinθ (where b = sqrt(g/L))
I want to use ode45 to solve these equations.
I tried following the link: https://www.mathworks.com/help/matlab/ref/ode45.html but I got errors on my code.
m-file
function dydt = spendn(t,y)
dydt = [u; -sinu];
In command window:
[t,y] = ode45(@spendn,[0 7],[0; 1.57]);
I am doing something wrong here, pls help.
  댓글 수: 1
Jan
Jan 2017년 11월 16일
편집: Jan 2017년 11월 16일
Please post the complete error message.
The conversion from
y(1) = dθ/dt = ω = u_θ
y(2) = dω/dt = -b^2*sinθ (where b = sqrt(g/L))
to
dydt = [u; -sinu];
seems to be too rough. Neither "u" not "sinu" are defined.

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

답변 (1개)

Star Strider
Star Strider 2017년 11월 16일
Try this:
dydt = [u; -sin(u)];
  댓글 수: 4
Alexandros
Alexandros 2017년 11월 17일
Now I get this error:
Error using odearguments (line 92)
SPENDN returns a vector of length 4,
but the length of initial conditions vector is 2. The
vector returned by SPENDN and the initial conditions
vector must have the same number of
elements.
Error in ode45 (line 113)
[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn, ...
Star Strider
Star Strider 2017년 11월 17일
Use this:
function dudt = spendn(t,u)
dydt = [u(2); -sin(u(1))];
end
or this:
spendn = @(t,u) [u(2); -sin(u(1))];
Either of these will work.

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

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by