Message Boards Message Boards

Use NIntegrate in NDSolve for two-dimensional variable X[r,t]?

I know the question about the use of NIntegrate inside of NDSolve has been asked -and answered- many times. Unfortunately I don't understand how to do the auxilliary function for a two dimensional variable -or maybe I am just not familiar enough with the syntax.

In my problem I have a system of differential equations that describes the time development [t] of a particle density spatially resolved [r]. However now I would also need the particle count at any time point and therefore wanted to integrate only the spatial coordinate numerically. (As this particle count should feed back to the differential equations, I cannot simply evaluate it afterwards.)

A shortened version of the problem and my try for the auxilliary function:

sol = NDSolve[{D[B[t, r], t] ==..., {D[A[t, r], t]==...,

Now I want to integrate B[t,r] over r, holding t constant. NIntegrate[B[t, r] r, ?t?, { r, rmin, rmax}]

TEST[t, r] == Btotal[B[t,r]],

Auxilliary function:

Btotal[B_Real]:= NIntegrate[r*B,{ r, rmin, rmax}]

OR

TEST[t, r] == Btotal[B[t, r], t, r],

Auxilliary function:

Btotal[B_Real, t_Real, r_Real] := NIntegrate[r*B[t, r], { r, rmin, rmax}];

So it seems I didn't manage to address the B[t,r] correctly...

Thank you very much for any help!

Felix

Here is some simplified version of the code I have. (for constant Q it works of course.)

rmin = 0;
rmax = 1;
tmax = 0.3;

s = NDSolve[{
   D[B[t, r], t] == +0.5*A[t, r] B[t, r] - 0.3 Q[t, r] B[t, r],
   D[A[t, r], t] == -0.5* A[t, r] B[t, r] + 0.3 Q[t, r] B[t, r],
   D[Q[t, r], t] == 2*Pi*NIntegrate[r B[t, r], {r, rmin, rmax}],
   B[0, r] == 1,
   A[0, r] == 100,
   Q[0, r] == 0},
  {B[t, r], A[t, r], Q[t, r] }, {t, 0, tmax}, {r, rmin, rmax},
  MaxStepFraction -> .005, MaxSteps -> 10000]
POSTED BY: Felix Keber
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract