Re:Integrate with If--NDSolve
- To: mathgroup at smc.vnet.net
- Subject: [mg22298] Re:[mg22180] Integrate with If--NDSolve
- From: bernd at bio.vu.nl (Bernd Brandt)
- Date: Thu, 24 Feb 2000 03:01:15 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
Hi,
Is there a way to do something similar with NDSolve. I would like to
solve a PDE with a discontinuity. At this point the loss term and the
diffusion constant change.
How can i tell NDSolve where this discontinuity is?
The problem for dCon/dt==0 looks like this. At x==2 there should be a
discontinuous derivative. However Con''[x]==0 is also a solution at
this point (then 0 == Dco * 0 )
Dco2[x_] := 1 /; x <= 2
Dco2[x_] := 10 /; x > 2
Loss2[x_, Con_] := 10 Con / (2 + Con) /; x <= 2 && Con > 0
Loss2[x_, Con_] := 0 /; x > 2
sol = NDSolve[{0 == Dco2[x] Con''[x] - Loss2[x, Con[x]], Con'[0] == 0,
Con[0] == 0.022}, Con, {x, 0, 3}]
Regards,
Bernd
on 00.2.17 3:24 PM, Johan Berglind,5879 at johanbe at chl.chalmers.se wrote:
> Why does
>
> Integrate[If[Sin[t] > 0, 1, 0] , {t, -Pi, Pi}]
>
> evaluate to 2Pi?
>
> Plot[If[Sin[t] > 0, 1, 0] , {t, -Pi, Pi} ]
>
> looks all right.
>
>
> Puzzled,
>
> Johan Berglind,
> Chalmers, Goteborg,
> Sweden.
>
This is of course wrong but I would not in general recommend trying this
sort of thing. When you use Integrate Mathematica has to find an
anti-derivative and in this case the antiderivative has a jump at 0.
Integrate is not very good at dealing with singularities. In some cases like
this one you can deal with this problem by adding the jump point to the
range of integration as in :
In[15]:=
Integrate[If[Sin[t] > 0, 1, 0] , {t, -Pi, 0, Pi}]
Out[15]=
Pi
Or if you are satisfied with a numerical answer use NIntegrate:
In[16]:=
NIntegrate[If[Sin[t] > 0, 1, 0] , {t, -Pi, Pi}]
Out[16]=
3.14159