I am trying to simulate a system of $n$ pendulums with some friction in Mathematica 9. This is the code I am using:
nPendulos = 3;
tiempoFinal = 20;
fps = 30;
g = 9.81;
r = 0.5;
x[0][t_] := 0
y[0][t_] := 0
CondicionesIniciales =
Join[Table[x[n][0] == n, {n, 1, nPendulos}], Table[y[n]'[0] == 0, {n, 1, nPendulos}]];
Restricciones = Table[(x[n][t] - x[n-1][t])^2 + (y[n][t] - y[n - 1][t])^2 == 1, {n, 1, nPendulos}];
EqNewton = Join[Table[x[n]''[t] == λ[n][t] (x[n][t] - x[n - 1][t]) -
λ[n + 1][t] (x[n + 1][t] - x[n][t]) - r x[n]'[t], {n, 1, nPendulos - 1}],
Table[y[n]''[t] == λ[n][ t] (y[n][t] - y[n - 1][t]) - λ[n + 1][t]
(y[n + 1][t] - y[n][t]) - g - r y[n]'[t], {n, 1, nPendulos - 1}],
{x[nPendulos]''[t] == λ[nPendulos][ t] (x[nPendulos][t] - x[nPendulos - 1][t]) - r x[nPendulos]'[t]},
{y[nPendulos]''[t] == λ[nPendulos][t] (y[nPendulos][t] - y[nPendulos - 1][t]) - g
- r y[nPendulos]'[t]}];
Vars = Flatten@Table[{λ[n], x[n], y[n]}, {n, 1, nPendulos}];
Sol = NDSolve[{EqNewton, Restricciones, CondicionesIniciales}, Vars,
{t, 0, tiempoFinal}, AccuracyGoal -> 2, PrecisionGoal -> 2, MaxStepSize -> 0.01,
Method -> {"IndexReduction" -> {True, "ConstraintMethod" -> {"Projection",
"Invariants" -> Restricciones}}}];
It works fine when the friction is high or nPendulos (number of pendulus) is low. But for example for nPendulos = 4 and r = 0.5 or nPendulos = 3 and r = 0.15, I get things like
NDSolve::ndcf: Repeated convergence test failure at t == 0.93296875`; unable to continue.
NDSolve::ndsz: At t == 2.5562500630525498`, step size is effectively zero; singularity or stiff system suspected.
I am almost sure that the physics behind the system is right, because the results for example when nPendulos = 2 or 3 are nice (see https://dl.dropboxusercontent.com/u/35192406/3_con_rozamiento.gif with friction or https://dl.dropboxusercontent.com/u/35192406/test2.gif with no friction)
Why is NDSolve failing? How can I make it work?
Subscript[]makes the code very unpleasant to read here. – Dr. belisarius Nov 25 '13 at 04:53x[n]instead ofSubscript[x, n]– Dr. belisarius Nov 25 '13 at 05:23"IndexGoal" -> 0seems key. Settinggravity = 1as in the example helps a lot, too. But I would not always get a complete solution depending on how I changed the parameters. Also solutions found with different settings did not always agree very well. I didn't think I found a definitive answer, and the best I could do was give the OP something to play with. – Michael E2 Dec 06 '13 at 15:40