Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #5413 > unrolled thread
| Started by | Howard <hcohl@nist.gov> |
|---|---|
| First post | 2011-10-06 08:22 +0000 |
| Last post | 2011-10-08 18:46 +0000 |
| Articles | 3 — 3 participants |
Back to article view | Back to comp.soft-sys.math.mathematica
Table NDSolve Plot Howard <hcohl@nist.gov> - 2011-10-06 08:22 +0000
Re: Table NDSolve Plot "Dr. Wolfgang Hintze" <weh@snafu.de> - 2011-10-07 08:47 +0000
Re: Table NDSolve Plot Helen Read <readhpr@gmail.com> - 2011-10-08 18:46 +0000
| From | Howard <hcohl@nist.gov> |
|---|---|
| Date | 2011-10-06 08:22 +0000 |
| Subject | Table NDSolve Plot |
| Message-ID | <j6jofa$m25$1@smc.vnet.net> |
Hi. I know this is a basic question, but I am having difficulty finding how to do this in Mathematica.
I want to make a plot with multiple solutions of an ordinary differential equation which I want to generate using NDSolve. For instance, let me take
k=0.999
h=0.0
n=0.0
s = NDSolve[{(1 - z^2) (1 - k^2 z^2) w''[z] - z (1 + k^2 - 2 k^2 z^2) w'[z] + (h - n (n + 1) k^2 z^2) w[z] == 0, w[2] == 1/2 Log[3], w'[2] == -1/3.}, w, {z, 11/10, 3}]
Plot[Evaluate[w[z] /. s], {z, 11/10, 3}, PlotRange -> All]
This shows the plot for this function.
I would like to generate solutions for say 10 k's, for instance 10 k's between .9 and 1.0 and put them all on the same plot. I'm guessing I can do this with Plot, NDSolve, Table, etc.
Can you help me figure out the syntax?
Thanks, Howard
[toc] | [next] | [standalone]
| From | "Dr. Wolfgang Hintze" <weh@snafu.de> |
|---|---|
| Date | 2011-10-07 08:47 +0000 |
| Message-ID | <j6meam$76r$1@smc.vnet.net> |
| In reply to | #5413 |
"Howard" <hcohl@nist.gov> schrieb im Newsbeitrag
news:j6jofa$m25$1@smc.vnet.net...
> Hi. I know this is a basic question, but I am having difficulty
> finding how to do this in Mathematica.
>
> I want to make a plot with multiple solutions of an ordinary
> differential equation which I want to generate using NDSolve. For
> instance, let me take
>
> k=0.999
> h=0.0
> n=0.0
> s = NDSolve[{(1 - z^2) (1 - k^2 z^2) w''[z] - z (1 + k^2 - 2 k^2 z^2)
> w'[z] + (h - n (n + 1) k^2 z^2) w[z] == 0, w[2] == 1/2 Log[3], w'[2]
> == -1/3.}, w, {z, 11/10, 3}]
> Plot[Evaluate[w[z] /. s], {z, 11/10, 3}, PlotRange -> All]
>
> This shows the plot for this function.
>
> I would like to generate solutions for say 10 k's, for instance 10
> k's between .9 and 1.0 and put them all on the same plot. I'm
> guessing I can do this with Plot, NDSolve, Table, etc.
>
> Can you help me figure out the syntax?
>
> Thanks, Howard
>
The trick is to use DisplayFunction to create various plots "silently"
and then display them using Show.
Here is an example of how to combine just two plots
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)*D[w[z], z] + (1 - z^2)*(1 - k^2*z^2)*D[w[z], {z, 2}] == 0,
w[2] == 1,
Derivative[1][w][2] == -1}, w[z], {z, 1.1, 3.}];
p[1] = Plot[Evaluate[w[z] /. s], {z, 1.1, 3.}, PlotStyle -> Automatic,
DisplayFunction -> Identity];
p[2] = Plot[(1/2)*Log[(z + 1)/(z - 1)], {z, 1.1, 3.}, PlotStyle ->
Automatic, DisplayFunction -> Identity];
Show[{p[1], p[2]}, DisplayFunction -> $DisplayFunction];
Wolfgang
[toc] | [prev] | [next] | [standalone]
| From | Helen Read <readhpr@gmail.com> |
|---|---|
| Date | 2011-10-08 18:46 +0000 |
| Message-ID | <j6q5pp$ovv$1@smc.vnet.net> |
| In reply to | #5463 |
What version of Mathematica are your using? The DisplayFunction business
has not been necessary since approximately version 6.
Try your example without all the DisplayFunction->Identity and
DisplayFunction->$DisplayFunction and it will work just fine, as long as
you omit the semi-colon at the end of the Show[].
And if you need a semi-colon at the end of the Show (for example if it's
inside a Module with other stuff after the Show), just wrap it in Print.
Print[Show[]];
Helen
On 10/7/2011 4:47 AM, Dr. Wolfgang Hintze wrote:
>
>>
> The trick is to use DisplayFunction to create various plots "silently"
> and then display them using Show.
>
> Here is an example of how to combine just two plots
>
> 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)*D[w[z], z] + (1 - z^2)*(1 - k^2*z^2)*D[w[z], {z, 2}] == 0,
> w[2] == 1,
> Derivative[1][w][2] == -1}, w[z], {z, 1.1, 3.}];
> p[1] = Plot[Evaluate[w[z] /. s], {z, 1.1, 3.}, PlotStyle -> Automatic,
> DisplayFunction -> Identity];
> p[2] = Plot[(1/2)*Log[(z + 1)/(z - 1)], {z, 1.1, 3.}, PlotStyle ->
> Automatic, DisplayFunction -> Identity];
> Show[{p[1], p[2]}, DisplayFunction -> $DisplayFunction];
>
> Wolfgang
>
>
[toc] | [prev] | [standalone]
Back to top | Article view | comp.soft-sys.math.mathematica
csiph-web