Message Boards Message Boards

GROUPS:

Avoid error while using NDSolve on theses differential equations?

Posted 2 months ago
293 Views
|
2 Replies
|
4 Total Likes
|

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.

2 Replies

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.]

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}]

enter image description here

Cheers,

Marco

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract