MathGroup Archive 2008

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: DSolve Issues

  • To: mathgroup at smc.vnet.net
  • Subject: [mg88356] Re: DSolve Issues
  • From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
  • Date: Sat, 3 May 2008 06:13:47 -0400 (EDT)
  • Organization: The Open University, Milton Keynes, UK
  • References: <fveguc$5ed$1@smc.vnet.net>

donkorgi12 wrote:

> I am solving the following Differential Equation
> 
> Phi''[r]+2*r^(-1)Phi'[r]+0.104479*Phi[r]==0 and Phi[0]==K (some
> constant)   ; kinda has a cos/sin solution
> 
> 2.71828^(-0.323232 \[ImaginaryI] r) ((0.+
>      0. \[ImaginaryI]) + (0.+ 0. \[ImaginaryI]) 2.71828^(
>     0.646465 \[ImaginaryI] r) + (0.+ 1.54687 \[ImaginaryI]) K - (0.+
>       1.54687 \[ImaginaryI]) 2.71828^(0.646465 \[ImaginaryI] r) K)
> 
> all divided by r.
> 
> My problem is that Mathematica is not treating those "zeros".... as
> well zeros. Thus, the solution cannot really be used. In fact, if I
> manually reproduce the solution and remove those "zeros", then the
> solution is fine.

Say your solution is called sol. You can get ride of the spurious zeros 
yield by numerical impression thanks to the command *Chop[]*. For instance,

In[1]:= sol = 2.71828^(-0.323232 I r) ((0. +
        0. I) + (0. + 0. I) 2.71828^(0.646465 I r) + (0. +
         1.54687 I) K - (0. + 1.54687 I) 2.71828^(0.646465 I r) K) // Chop

Out[1]=

                                0.646465 I r
1.54687 I K - 1.54687 I 2.71828             K
---------------------------------------------
                     0.323232 I r
              2.71828


It would be better to use exact arithmetic as early as possible, either 
by entering exact numbers (e.g. 1.0 is not the same thing as 1 from a 
computational point of view since the underlaying computer 
representation is not the same at all) or using the built-in function 
*Rationalize[]*.

Moreover, one can convert exponential function thanks to the function 
*ExpToTrig[]*. For instance,

In[2]:= ode = Rationalize[Phi''[r] + 2*r^(-1) Phi'[r] + 0.104479*Phi[r], 0];
sol = DSolve[{ode == 0, Phi[0] == K}, Phi, r]
Phi[r] /. sol[[1]] // ExpToTrig

Out[3]=
                                        1/500 I Sqrt[104479] r
                           500 I (-1 + E                      ) K
{{Phi -> Function[{r}, -(-----------------------------------------)]}}
                           (I Sqrt[104479] r)/1000
                          E                        (Sqrt[104479] r)

Out[4]=

         1                      Sqrt[104479] r          Sqrt[104479] r
-(-------------- (500 I K (Cos[--------------] - I Sin[--------------])
   Sqrt[104479] r                    1000                    1000

                 Sqrt[104479] r          Sqrt[104479] r
       (-1 + Cos[--------------] + I Sin[--------------])))
                      500                     500

[snip]

> Yet, Mathematica treats those "zeros" as something else.

No. It treats them as *inexact* numbers, which is fine since you are 
using inexact (aka *machine-size*) arithmetic.

The following multimedia demo illustrates strikingly the difference 
between floating-point arithmetic and arbitrary/exact arithmetic.

http://www.wolfram.com/technology/guide/precisiontracking.html


Best regards,
-- Jean-Marc



  • Prev by Date: Re: Wolfram Workbench user experiences
  • Next by Date: Options
  • Previous by thread: Re: DSolve Issues
  • Next by thread: Locator