function T= pendulum( L, a0 )%PENDULUM Summary of this function goes here
% Detailed explanation goes here
%initializing variables
alpha = a0;delta_t = 1*10^-6;g = 9.8;stop = false;theta = a0;t = 0;omegalast =0%Set stop = falsE so that loop stop isn't true at start
while stop == false;%increment t for each step into loop
t = t+ delta_t;%compute alpha using given formula
alpha = - g/L*sin(theta);%compute omega as alpha times timestep, delta_t
omega = alpha*delta_t;%theta is then theta plus omega times delta_t
theta = theta + omega*delta_t;%check to see if pendulum speed has
%slowed down from the last timestep
%This indicatest that pendulum is now past the
%minimum point so stop program
if abs(omega) <abs(omegalast) stop = true;end%IF THE SOFTWARE SHOULD STOP IT IS NOW SET TO DO SO
%SET OMEGALAST EQUAL TO OMEGA FOR CHECK IN NEXT TIME STEP
omegalast = omega;end%COMPUTE PERIOD AS 4 TIMES ELAPSED TIME TO BOTTOM OF PENDULUM
T = 4*t;end
This isn't producing the right answers,and I don't know why. Perhaps a physic or math major can help me?
The problem is stated as:
* Write a function called pendulum that is called like this: T = pendulum(L,a0), where all arguments are scalars and a0 is a positive number less than π. The function calculates the period T of a simple pendulum, which is the time required for a weight attached to a rod of length L and negligible weight to start from rest, swing with no friction under the influence of gravity from an initial angle a0, to – a0 and back to a0 again, as shown in the figure. The motion is determined by physics using the following definitions, where units [square brackets] are provided but are not needed: θ = angle [radians]
Best Answer