Re: Manipulate a Plot of Evaluate DSolve

• To: mathgroup at smc.vnet.net
• Subject: [mg127500] Re: Manipulate a Plot of Evaluate DSolve
• From: Juan Barandiaran <barandiaran.juan at gmail.com>
• Date: Mon, 30 Jul 2012 03:46:44 -0400 (EDT)
• Delivered-to: l-mathgroup@mail-archive0.wolfram.com
• Delivered-to: l-mathgroup@wolfram.com
• Delivered-to: mathgroup-newout@smc.vnet.net
• Delivered-to: mathgroup-newsend@smc.vnet.net
• References: <20120729070521.C7CB3684D@smc.vnet.net> <CAEtRDSfuzxN12HoeTLPuZGmegBOpubxd3J_g0ESgnT8=KQStBw@mail.gmail.com>

```Thanks for your answer Bob,
Of course your solution works, but I still don't understand why mine
doesn't and I cannot use your proposed approach because the way you write
the problem it is easy for Mathematica to solve the DSolve.
And this is just a simple example, in my real problem the DSolve cannot be
solved analytically.
This is why I tried to express the function as:

{{y -> Function[{x}, DSolve[y'[x] == Cos[coef *x], y, x]]}}

, which is something like the output I get from my DSolve.

Juan

2012/7/29 Bob Hanlon <hanlonr357 at gmail.com>

> Clear[func];
>
> func[coef_, c_, x_] =
>  y[x] /. DSolve[{y'[x] == Cos[coef*x], y[0] == c}, y[x], x][[1]] //
>   Simplify
>
> c + Sin[coef*x]/coef
>
>
> Manipulate[Plot[Evaluate[
>    func[coef, c, x] /.
>     c -> Range[5]],
>   {x, -10, 10},
>   PlotRange -> {-5, 10}],
>  {{coef, 1}, 0.1, 5, 0.01,
>   Appearance -> "Labeled"}]
>
>
> Bob Hanlon
>
>
> On Sun, Jul 29, 2012 at 3:05 AM,  <barandiaran.juan at gmail.com> wrote:
> > Hi,
> >
> > I'm trying to Manipulate a Plot of a quite difficult function which
> involves solving a differential equation, but cannot be solved analytically.
> >
> > To try to simplify the example and simulate it, let's assume that we
> have the following function:
> >
> > func[coef_] = {{y -> Function[{x}, DSolve[y'[x] == Cos[coef *x], y, x]]}}
> >
> > Manipulate[Plot[{{Evaluate[y[x] /. func[coef] /. C[1] -> {Range[-5,
> 0]}]}}, {x, -10, 10}], {{coef , 1}, 0.1, 5}]
> >
> > I get an error: DSolve::dsvar: "-9.99959 cannot be used as a variable"
> >
> > I think that this is because Manipulate assigns a value to x (=
> -9.99959) BEFORE solving the DSolve, even though to avoid it I'm using the
> Evaluate function, which should process the function before assigning a
> value to x.
> >
> > But the thing is that the "coef" to be Manipulated is at the same
> "level" as the x in the Manipulate block, so probably if I need the coef to
> solve the DSolve, I also have the x that gives me an error.
> >
> > Is there any workaround? I guess I'm not understanding properly how
> Mathematica processes these simple expressions.
> >
> > Thanks, Juan
> >
>

```

• Prev by Date: Re: Heat Equation on a surface sphere using NDSolve?
• Next by Date: Re: Manipulate a Plot of Evaluate DSolve
• Previous by thread: Re: Manipulate a Plot of Evaluate DSolve
• Next by thread: Re: Manipulate a Plot of Evaluate DSolve