Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #5483

Re: Table NDSolve Plot

From Peter Pein <petsie@dordos.net>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: Table NDSolve Plot
Date 2011-10-07 08:56 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <j6merd$7f4$1@smc.vnet.net> (permalink)
References <j6joh8$m3g$1@smc.vnet.net>

Show all headers | View raw


Am 06.10.2011 10:23, schrieb Howie:
> I know this is a basic question, but I am having a hard time figuring
> this out on my own.
> 
> I would like to numerically solve an ordinary differential equation
> with a parameter which varies over a range of numbers and plot all the
> solutions with different values of the parameter on the same plot.
> Also, I would like to be able to then over-plot another solution on
> the same plot.
> 
> For instance:
> 
> h=0
> n=0
> k=0.25
> s = NDSolve[{(h - k^2 n (1 + n) z^2) w[z] -
>      z (1 + k^2 - 2 k^2 z^2) Derivative[1][w][
>        z] + (1 - z^2) (1 - k^2 z^2) (w^\[Prime]\[Prime])[z] == 0,
>    w[2] == 1, w'[2] == -1}, w, {z, 1.1, 3.0}]
> Plot[Evaluate[w[z] /. s], {z, 1.1, 3.0}, PlotStyle -> Automatic]
> Plot[1/2 Log[(z + 1)/(z - 1)], {z, 1.1, 3.0}, PlotStyle -> Automatic]
> I would like to do this for instance 10 increments of k from 0 to 1,
> and also the Log plot, all on the same plot.
> 
> Thanks!
> 

Hi,

 why not solving the differential equation exactly? Then create all
plots you want and display these together with the log-plot using Show.

something like:

In[1]:= f[z_] = FullSimplify[With[{h = 0, n = 0},
    w[z] /. First[DSolve[{(1 - z^2)*(1 - k^2*z^2)*Derivative[2][w][z] -
z*(1 + k^2 - 2*k^2*z^2)*
           Derivative[1][w][z] + (h - n*(n + 1)*k^2*z^2)*w[z] == 0, w[2]
== Log[3]/2,
        Derivative[1][w][2] == -(1/3)}, w, z]]], 0 < k < 1 && 1/k < z]
Out[1]= (1/6)*(2*I*Sqrt[3 - 12*k^2]*(EllipticF[ArcSin[2], k^2] -
EllipticF[ArcSin[z], k^2]) + Log[27])
In[2]:= Show[Join[{Plot[(1/2)*Log[(z + 1)/(z - 1)], {z, 1.1, 3.},
PlotStyle -> Thick]},
   Table[Plot[f[z], {z, 1, 3}, PlotStyle -> Hue[k]], {k, Range[9]/10}]],
PlotRange -> {All, All},
  Axes -> None, Frame -> True, GridLines -> {Automatic,
(1/4)*Log[3]*Range[5]},
  GridLinesStyle -> LightGray]

Peter

Back to comp.soft-sys.math.mathematica | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

Table NDSolve Plot Howie <hcohl001@gmail.com> - 2011-10-06 08:23 +0000
  Re: Table NDSolve Plot Peter Pein <petsie@dordos.net> - 2011-10-07 08:56 +0000

csiph-web