MATLAB Answers

## I am modeling a set of pendulums, can anyone explain why the Theta value is coming out the same for all of them when my time and period values are working out like they should?

Asked by Brady Williams

### Brady Williams (view profile)

on 24 Apr 2016
Latest activity Answered by Vaibhav Awale

### Vaibhav Awale (view profile)

on 3 May 2016
clear, clc, close all
G=9.81; i=1;
while i==1 %Inputting length for longest pendulum and checking if it meets the criteria lin=input('Please input a valid length for the longest pendulum in cm: '); L(1)=lin/100; chk=(12/26)^2 * L(1); if L(1)<=0.9 if chk>=0.05 i=0; end end end
for c=2:15 %Finding the lengths of the other pendulums from the first one. L(c)=(12/(12+c-1))^2 *L(1); end
AngMax=14;
for i=1:15 T(i)=2*pi*sqrt(L(i)/G); t(i,:)=linspace(0,T(i)); Theta(i,:)=AngMax.*sin(t(i,:).*sqrt(G/L(i))); x(i,:)=L(i).*sind(Theta(i,:)); y(i,:)=-abs(L(i).*cosd(Theta(i,:))); end
This is the code I am using, I have tried everything I can think of and no matter what the Theta variable has the same value for all of the pendulums all of the time.

#### 0 Comments

Sign in to comment.

## 1 Answer

### Vaibhav Awale (view profile)

Answer by Vaibhav Awale

### Vaibhav Awale (view profile)

on 3 May 2016

Hi Brady,
You are getting the same value for Theta variable because your t vector is something like:
t(i,:) = [0, T(i)/100, 2*T(i)/100, ..., T(i)];
Now,
T(i) = 2*pi*sqrt(L(i)/G);
So inside the sin function while calculating Theta(i), the following happens:
sin(t(i,:).*sqrt(G/L(i))) = sin(t(i,:).*(2*pi/T(i))) = sin([0, (2*pi)/100, 2*(2*pi)/100,...,(2*pi)])
Hence, regardless of value of T(i), you are always getting the same values for Theta variable.
If you expect to see value of Theta with respect to time, the time vector needs to be the same for each pendulum (i.e. t(i,:) can't be defined as you have done). Then you will observe that at different time instant, value of Theta is different for different pendulum.
I hope this helps.
Regards,
Vaibhav

#### 0 Comments

Sign in to comment.