Péndulo con oscilaciones amortiguadas
Script
# Gravity
g = 9.81
# Mass
m = 3
# Damping
γ = 0.791
# Length
L = 2
# Initial Position and initial velocity
θ0 = 3 pi/4
ω0 = 0
# System of ODEs
θ'(t, θ, ω) = ω
ω'(t, θ, ω) = -γ/m ω - g / L sin(θ)
# Solve the system
NSolveODE({θ', ω'}, 0, {θ0, ω0}, 40)
SetVisibleInView(numericalIntegral1, 1, false)
SetVisibleInView(numericalIntegral2, 1, false)
# Plot the pendulum
# first get values of theta
len = Length(numericalIntegral1)
c = Slider(0, 1, 1 / len, 1, 100, false, true, true, false)
SetVisibleInView(c, 1, false)
# calculate position
xp = L sin(y(Point(numericalIntegral1, c)))
yp = -L cos(y(Point(numericalIntegral1, c)))
# plot mass
A = (xp, yp)
ShowLabel(A, false)
SetColor(A, "Red")
SetPointSize(A, 9)
# plot bar
f = Segment((0, 0), A)
SetCaption(f, "L")
StartAnimation()