Equation of motion of Non linear pendulum

10 visualizaciones (últimos 30 días)
KLETECH MOTORSPORTS
KLETECH MOTORSPORTS el 4 de Nov. de 2020
Comentada: Bjorn Gustavsson el 4 de Nov. de 2020
tspan=[0,2*pi];
u0=[pi/4;0];
[t,u]=ode45(@pendulum,tspan,u0,[]);
plot(t,u(:,1),'b-', 'LineWidth', 2)
xlabel('time')
ylabel('angle')
function zdot = pend (t,z)
wsq = 1.56; % specify a value of w"2
t = time;
z = [z (l) ; z ( 2)] = [theta; thetadot]
zdot = [z (2) ; -wsq* sin (z(l))];
end
This doesn't seem to be working. I'm trying to plot the discplacement versus time and velocity versus time. Any idea as to what the problem mightbe?
I got this from Rudra pratap. I've attached a link to the book, it's on page 159 (173 by docs)

Respuesta aceptada

Bjorn Gustavsson
Bjorn Gustavsson el 4 de Nov. de 2020
Note that the function you use for the input-argument to ode45 is pendulum while the function you implemented for the pendulum has the name pend. They should be the same. When that's fixed there seems to be no major problems with your code:
u0=[pi/4;0];
pend = @(t,z) [z(2);-1.56*sin(z(1))];
figure
tspan=[0,12*pi]; % just a slightly longer time-span
[t,u]=ode45(pend,tspan,u0,[]);
plot(t,u)
HTH
  3 comentarios
KLETECH MOTORSPORTS
KLETECH MOTORSPORTS el 4 de Nov. de 2020
i got this error
Bjorn Gustavsson
Bjorn Gustavsson el 4 de Nov. de 2020
Ok, that is because your script is named pend.m and then matlab doesn't like the naming-confusion with a variable with that name in the script. You should be fine if you rename the variable to someting like pendODE for example.
HTH

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Programming en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by