Re: How to avoid repeated calculation in NDSolve ?
- To: mathgroup at smc.vnet.net
- Subject: [mg117004] Re: How to avoid repeated calculation in NDSolve ?
- From: Peter Pein <petsie at dordos.net>
- Date: Mon, 7 Mar 2011 05:48:29 -0500 (EST)
- References: <ikvou0$fa7$1@smc.vnet.net>
Am 06.03.2011 11:50, schrieb t. shim:
> Hi,
>
> As the samplke list below, the rhs of equations in NDSolve may have
> many repeated appearance of the same expression such as (\[Mu][t]^2 +
> \[Nu][t]^2) in the denominator.
> In Fortran, we first write r = (\[Mu][t]^2 + \[Nu][t]^2) and in what
> follows use r insted of (\[Mu][t]^2 + \[Nu][t]^2).
> Tell me if such can be applied also in mathematica.
>
> Regards, t. shim
>
> NDSolve[
> {p\[Mu]'[t] ==
> 1/2 (2 \[Mu][
> t] (1/2 (
> p\[Mu][t]^2 + p\[Nu][t]^2-4)/(\[Mu][t]^2 + \[Nu][t]^2) -
> (1 - \[Gamma])/2 (\[Mu][t] p\[Mu][t] - \[Nu][t] p\[Nu][t])^2/ (\[Mu]
> [t]^2 + \[Nu][t]^2)^2) +
> (1 - \[Gamma]) 1/(\[Mu][t]^2 + \[Nu][t]^2)^2 \[Nu][t] (\[Mu][t] p\[Mu]
> [t] -
> \[Nu][t] p\[Nu][t]) (\[Nu][t] p\[Mu][t] + \[Mu][t] p\[Nu][t])),
> p\[Mu]'[t] == (mu, nu interchanged)
> ...
>
Hi,
use With:
With[{r = \[Mu][t]^2 + \[Nu][t]^2},
(1/2)*(((1 - \[Gamma])*\[Nu][t]*
(p\[Nu][t]*\[Mu][t] + p\[Mu][t]*\[Nu][t])*(p\[Mu][t]*\[Mu][t] -
p\[Nu][t]*\[Nu][t]))/r^2 +
2*\[Mu][t]*(-(((1 - \[Gamma])*(p\[Mu][t]*\[Mu][t] -
p\[Nu][t]*\[Nu][t])^2)/(2*r^2)) +
(-4 + p\[Mu][t]^2 + p\[Nu][t]^2)/(2*r)))
]
hth,
Peter