[Date Index]
[Thread Index]
[Author Index]
Re: Re: NDSolve Question
*To*: mathgroup at smc.vnet.net
*Subject*: [mg86459] Re: [mg86427] Re: NDSolve Question
*From*: Bob Hanlon <hanlonr at cox.net>
*Date*: Tue, 11 Mar 2008 05:45:01 -0500 (EST)
*Reply-to*: hanlonr at cox.net
The e-mail that was quoted in your reply was not what I sent. Some characters (plus signs) got lost on the way. The function was modified to x[t] plus 2 in the DSolve example and to q plus 2 in definition of f. I have resent the input/output.
f[q_?NumericQ] := q;
This function is not very useful as an example since
DSolve[{x'[t] == x[t], x[0] == 0}, x[t], t][[1]]
{x[t] -> 0}
With a slight change
DSolve[{x'[t] == x[t] + 2, x[0] == 0}, x[t], t][[1]]
{x[t] -> 2*(-1 + E^t)}
f[q_?NumericQ] := q + 2;
Note that NumericQ is better than NumberQ so that f will evaluate with arguments
like Pi or E
f[3 Pi]
2 + 3*Pi
sol = NDSolve[{x'[t] == f[x[t]], x[0] == 0}, x, {t, 0, 1}][[1]];
Plot[x[t] /. sol, {t, 0, 1}]
Bob Hanlon
---- Jerry <Jer75811 at yahoo.com> wrote:
> Sir, I tried your suggestions but I never get a plot unless
> I use the init. condition x[0] == 1 as suggested by
> jwmerrill. So I guess I still don't understand the issues.
> Thanks.
>
> Bob Hanlon wrote:
> > f[q_?NumericQ] := q;
> >
> > This function is not very useful as an example since
> >
> > DSolve[{x'[t] == x[t], x[0] == 0}, x[t], t][[1]]
> >
> > {x[t] -> 0}
> >
> > With a slight change
> >
> > DSolve[{x'[t] == x[t] 2, x[0] == 0}, x[t], t][[1]]
> >
> > {x[t] -> 2*(-1 E^t)}
> >
> > f[q_?NumericQ] := q 2;
> >
> > Note that NumericQ is better than NumberQ so that f will evaluate with arguments like Pi or E
> >
> > f[3 Pi]
> >
> > 2 3*Pi
> >
> > sol = NDSolve[{x'[t] == f[x[t]], x[0] == 0}, x, {t, 0, 1}][[1]];
> >
> > Plot[x[t] /. sol, {t, 0, 1}]
> >
> >
> > Bob Hanlon
> >
> > ---- Jerry <Jer75811 at yahoo.com> wrote:
> >> Sir, I tried this and I only get plot axes, no graph.
> >>
> >> f[q_?NumberQ] := q
> >> sol = NDSolve[{x'[t] == f[x[t]], x[0] == 0}, {x}, {t, 0, 1}]
> >> Plot[x[t] /. sol, {t, 0, 1}]
> >>
> >> In place of {x} in sol I tried x and x[t] with no change.
> >> In Plot I tried x instead of x[t], no help.
> >>
> >> Can you give me a successful example? Thanks.
> >>
> >>
> >>
> >>
> >> David Park wrote:
> >>> I found the answer, which is to use:
> >>>
> >>> f[q_?NumberQ]:= ...
> >>>
> >>> which prevents an initial evaluation.
> >>>
> >
> >
>
Prev by Date:
**Re: Re: definite integration of 1/a**
Next by Date:
**Re: symbolize in v.6**
Previous by thread:
**Re: NDSolve Question**
Next by thread:
**Re: NDSolve Question**
| |