Pendulum - %Assign time step (delta t) deltat=.01; %Assign...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
%Bryan Choquette %ME 082 %Week 4 Assignment clc clear all %Assign values to the constants g=9.81; L=1; %Create initial position of the rod, bob, and hinge data=([0 0;0 -L]); figure(1) axis([-2 2 -2 2]); rod = line('xdata',data(1,:),'ydata',data(2,:)); hinge = line(0,0,'marker','o'); bob = line('xdata',data(1,2),'ydata',data(2,2),'marker','o','markersize',15); %Assign initial conditions theta0=pi/4; thetadot0=0;%release from rest theta(1)=theta0; thetadot(1)=thetadot0; t0=0; t(1)=t0; k=1;
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: %Assign time step (delta t) deltat=.01; %Assign final time tfinal=25; %Create the loop and apply changes to the image while t<tfinal pause(.08) t(k+1)=t(k)+deltat; theta(k+1)=theta(k)+thetadot(k).*deltat; thetadot(k+1)=thetadot(k)-(((g/L).*sin(theta(k)).*deltat)); r=[cos(theta(k+1)) -sin(theta(k+1));sin(theta(k+1)) cos(theta(k+1))]; x=r*data; set(rod,'xdata',x(1,:),'ydata',x(2,:)); set(bob,'xdata',x(1,2),'ydata',x(2,2)); drawnow k=k+1; end...
View Full Document

This note was uploaded on 03/22/2012 for the course ENGINEERIM 1000 taught by Professor Ee during the Spring '12 term at Vermont Tech.

Ask a homework question - tutors are online