pendulum animation in octave code example
Example: pendulum animation in octave
clear all
close all
clc
%input
b=0.05;
g=9.8;
l=1;
m=1;
%initial conditions
initial=[0,3];
%time points
time=linspace(0,150,500);
%solve ode
[t,results]=ode45(@(t,theta) ode(t,theta,b,g,l,m),time,initial);
%plot
C=1
for a=1:length(results(:,1))
x1=-l*sind(results(a,1))
y1=-l*cosd(results(a,1))
plot([0,x1],[0,y1],'linewidth',1)
hold on
plot(x1,y1,'O','color','r')
axis([-.2,.2,-1.1,0])
pause(.006)
%storing frames in m
K(C)=getframe(gcf)
C=C+1
end
%creatig videofile for m
movie(K)
videofile=VideoWriter('forwardkinamatics.avi','uncompressed AVI')
open(videofile)
writeVideo(videofile,K)
close(videofile)
close all
plot(t,results(:,1))
hold on
plot(t,results(:,2))
axis([0,50,-8,8])
title("displacement vs velocity")
xlabel('time')
ylabel('plot')
legend('displacement','velocity')