'How do I get the pendulums to syncrochnize in my simulation?

I'm making a simulation of pendulum motion using a simple gravity pendulum in VPython. The relationships appear to be according to what is expected except, when I start a pendulum at a lower angle it does not have the same period as a pendulum of the same length. What could I do to fix it?

from visual import *

def mark(place, hue):
    
    marker = sphere(pos=place,radius = 0.2, color =hue)
  
def pendulum(bob,rod):
    if bob.pos.x < 0:
        bob.theta =-diff_angle(bob.pos,vec(0,-1,0))
    else:
        bob.theta =diff_angle(bob.pos,vec(0,-1,0))
    rod.long = mag(rod.axis)
    bob.acceleration= -(field_strength/rod.long)*sin(bob.theta)
    bob.velocity= bob.velocity + bob.acceleration
    bob.theta = bob.theta + bob.velocity*deltat
    bob.pos= vec(rod.long*sin(bob.theta),-rod.long*cos(bob.theta),0)
    mark(bob.pos,bob.color)
    rod.axis= vec(rod.long*sin(bob.theta),-rod.long*cos(bob.theta),0)
    if bob.pos == bob.initialplace:
        print(t)

theta0=1.5
theta1=1
rod1=10
rod2=10
rod3=40
ball1 = sphere(pos= vec(rod1*sin(theta0),-rod1*cos(theta0),0), radius=1, color=color.red)
ball1.theta = diff_angle(ball1.pos,vec(0,-1,0))
string1 = cylinder(pos = vec(0,0,0), radius= 0.1, axis=vec(0,-rod1,0), color=color.red)
ball1.velocity = 0
ball1.acceleration = 0
ball1.initialplace = ball1.pos

ball2 = sphere(pos= vec(rod2*sin(theta1),-rod2*cos(theta1),0), radius=1, color=color.white)
ball2.theta = diff_angle(ball2.pos,vec(0,-1,0))
string2 = cylinder(pos = vec(0,0,0), radius= 0.1, axis=vec(0,-rod2,0), color=color.white)
ball2.velocity = 0
ball2.acceleration = 0
ball2.initialplace = ball2.pos

ball3 = sphere(pos= vec(rod3*sin(theta0),-rod3*cos(theta0),0), radius=1, color=color.blue)
ball3.theta = diff_angle(ball3.pos,vec(0,-1,0))
string3 = cylinder(pos = vec(0,0,0), radius= 0.1, axis=vec(0,-rod3,0), color=color.blue)
ball3.velocity = 0
ball3.acceleration = 0
ball3.initialplace = ball3.pos


field_strength =9.81
t=0
deltat= 0.001

while t<500:
    rate(50)
    pendulum(ball1,string1)
    pendulum(ball2,string2)
    pendulum(ball3,string3)
    t = t+deltat


Solution 1:[1]

The period of a pendulum is independent of the maximum angle only if the angle is small (that is, if you can confound the angle with its sine). You are using quite large angles to make your comparison, and that's why you see the difference between the observed periods.

Writing equations in SO is very painful so I just refer you to this wikipedia page for more details.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 lr1985