Im trying to solve the differential equations and I keep getting the message error “NDSolve called with 2 arguments; 3 or more arguments are expected”. My code is
pend[a0, w0, k, l, wd] =
NDSolve[{a'[t] == w[t], w'[t] == -k w[t] - Sin[a[t]] + l Cos[q[t]],
q'[t] == wd, a[0] == a0, w[0] == w0, q[0] == 0}, {a, w, q}, {t, 0,
100}];
Any help with this is greatly appreciated.
danl
(Daniel Lichtblau)
February 13, 2019, 8:33pm
2
I got a different message.
It will be problematic whenever a0 et al are not numeric values, so I would recommend defining this using restricted pattern arguments and SetDelayed (:=, that is).
pend[a0_?NumberQ, w0_?NumberQ, k_?NumberQ, l_?NumberQ, wd_?NumberQ] :=
NDSolve[{a'[t] == w[t], w'[t] == -k w[t] - Sin[a[t]] + l Cos[q[t]],
q'[t] == wd, a[0] == a0, w[0] == w0, q[0] == 0}, {a, w, q}, {t,
0, 100}];
This evaluated, for example.
pend[1., 2., 3., 4., 5.]
mthiel
(Marco Thiel)
February 13, 2019, 9:40pm
3
I suppose that ParametricNDSolve could present another approach.
func = ParametricNDSolveValue[{a'[t] == w[t], w'[t] == -k w[t] - Sin[a[t]] + l Cos[q[t]], q'[t] == wd,
a[0] == a0, w[0] == w0, q[0] == 0}, {a, w, q}, {t, 0, 100}, {a0, w0, k, l, wd}]
pend[a0_, w0_, k_, l_, wd_] := func[a0, w0, l, k, wd]
Plot[#[t] & /@ pend[1., 2., 3., 4., 5.][[1 ;; 2]], {t, 0, 100}]
Cheers,
Marco