- Aug 15, 2006
- 375
- 1
- 81
I have a set of 6 coupled differential equations, the variables are U_x, U_y, U_z, b_x,b_y,b_z and the differential is over time. For brevity I won't post the equations themselves but they are effectively:
db/dt = x*b + i*u
and
du/dt = x*u + i*b +dQ/dx
Where the bold means vector and i is the imaginary number.
Normally this is an easy application of Runge Kutta in complex variables however there is a problem.
Q is defined as an integral which has to be numerically integrated.
Q = \int (du_y/dx + i*u_x) * exp(-|x-x'|) dx'
note the absoltue value, so really its 2 integrals from 0 -> infinity and -infinity -> 0
I have implemented a finite difference method to compute the derivatives: ( u_y(2) - u_y(1) )/ dx and a similar formula for dQ/dx. All this means that my code has to carry around u_y(2), u_y(1), and u_y(0) to calculate all the derivatives for each time step.
Now where I am confused is the step where the Runga - Kutta routine is computing the various K values, heres a snippet of the code in Fortran 90:
subroutine RK4(bx,by,bz,ux,uy,uy_1,uy_2,uz)
IMPLICIT NONE
complex :: bx,by,bz,ux,uy,uy_1,uy_2,uz
complex :: k11,k12,k13,k14,k21,k22,k23,k24,k31,k32,k33,k34,k41,k42,k43,k44,k51,k52,k53,k54,k61,k62,k63,k64
k11 = .5*dt*Eq1(bx,by,bz,ux,uy,uz)
k21 = .5*dt*Eq2(bx,by,bz,ux,uy,uz)
k31 = .5*dt*Eq3(bx,by,bz,ux,uy,uz)
k41 = .5*dt*Eq4(bx,by,bz,ux,uy,uy_1,uy_2,uz)
k51 = .5*dt*Eq5(bx,by,bz,ux,uy,uy_1,uz)
k61 = .5*dt*Eq6(bx,by,bz,ux,uy,uy_1,uz)
k12 = .5*dt*Eq1(bx+k11,by+k21,bz+k31,ux+k41,uy+k51,uz+k61)
k22 = .5*dt*Eq2(bx+k11,by+k21,bz+k31,ux+k41,uy+k51,uz+k61)
k32 = .5*dt*Eq3(bx+k11,by+k21,bz+k31,ux+k41,uy+k51,uz+k61)
k42 = .5*dt*Eq4(bx+k11,by+k21,bz+k31,ux+k41,uy+k51,uy_1,uy_2,uz+k61)
k52 = .5*dt*Eq5(bx+k11,by+k21,bz+k31,ux+k41,uy+k51,uy_1,uz+k61)
k62 = .5*dt*Eq6(bx+k11,by+k21,bz+k31,ux+k41,uy+k51,uy_1,uz+k61)
k13 = dt*Eq1(bx+k12,by+k22,bz+k32,ux+k42,uy+k52,uz+k62)
k23 = dt*Eq2(bx+k12,by+k22,bz+k32,ux+k42,uy+k52,uz+k62)
k33 = dt*Eq3(bx+k12,by+k22,bz+k32,ux+k42,uy+k52,uz+k62)
k43 = dt*Eq4(bx+k12,by+k22,bz+k32,ux+k42,uy+k52,uy_1,uy_2,uz+k62)
k53 = dt*Eq5(bx+k12,by+k22,bz+k32,ux+k42,uy+k52,uy_1,uz+k62)
k63 = dt*Eq6(bx+k12,by+k22,bz+k32,ux+k42,uy+k52,uy_1,uz+k62)
k14 = dt*Eq1(bx+k13,by+k23,bz+k33,ux+k43,uy+k53,uz+k63)
k24 = dt*Eq2(bx+k13,by+k23,bz+k33,ux+k43,uy+k53,uz+k63)
k34 = dt*Eq3(bx+k13,by+k23,bz+k33,ux+k43,uy+k53,uz+k63)
k44 = dt*Eq4(bx+k13,by+k23,bz+k33,ux+k43,uy+k53,uy_1,uy_2,uz+k63)
k54 = dt*Eq5(bx+k13,by+k23,bz+k33,ux+k43,uy+k53,uy_1,uz+k63)
k64 = dt*Eq6(bx+k13,by+k23,bz+k33,ux+k43,uy+k53,uy_1,uz+k63)
bx = bx + k11/6. + k12/3. + k13/3. + k14/6.
by = by + k21/6. + k22/3. + k23/3. + k24/6.
bz = bz + k31/6. + k32/3. + k33/3. + k34/6.
ux = ux + k41/6. + k42/3. + k43/3. + k44/6.
uy = uy + k51/6. + k52/3. + k53/3. + k54/6.
uz = uz + k61/6. + k62/3. + k63/3. + k64/6.
end subroutine RK4
I feel that I should be adding K5* to uy_1 and uy_2 during this step, where uy_1 and uy_2 are uy(1) and u_y(0) for the purposes of calculating derivatives.
I can elaborate on specifics more at request.
Does anyone have any suggestions/advice?
db/dt = x*b + i*u
and
du/dt = x*u + i*b +dQ/dx
Where the bold means vector and i is the imaginary number.
Normally this is an easy application of Runge Kutta in complex variables however there is a problem.
Q is defined as an integral which has to be numerically integrated.
Q = \int (du_y/dx + i*u_x) * exp(-|x-x'|) dx'
note the absoltue value, so really its 2 integrals from 0 -> infinity and -infinity -> 0
I have implemented a finite difference method to compute the derivatives: ( u_y(2) - u_y(1) )/ dx and a similar formula for dQ/dx. All this means that my code has to carry around u_y(2), u_y(1), and u_y(0) to calculate all the derivatives for each time step.
Now where I am confused is the step where the Runga - Kutta routine is computing the various K values, heres a snippet of the code in Fortran 90:
subroutine RK4(bx,by,bz,ux,uy,uy_1,uy_2,uz)
IMPLICIT NONE
complex :: bx,by,bz,ux,uy,uy_1,uy_2,uz
complex :: k11,k12,k13,k14,k21,k22,k23,k24,k31,k32,k33,k34,k41,k42,k43,k44,k51,k52,k53,k54,k61,k62,k63,k64
k11 = .5*dt*Eq1(bx,by,bz,ux,uy,uz)
k21 = .5*dt*Eq2(bx,by,bz,ux,uy,uz)
k31 = .5*dt*Eq3(bx,by,bz,ux,uy,uz)
k41 = .5*dt*Eq4(bx,by,bz,ux,uy,uy_1,uy_2,uz)
k51 = .5*dt*Eq5(bx,by,bz,ux,uy,uy_1,uz)
k61 = .5*dt*Eq6(bx,by,bz,ux,uy,uy_1,uz)
k12 = .5*dt*Eq1(bx+k11,by+k21,bz+k31,ux+k41,uy+k51,uz+k61)
k22 = .5*dt*Eq2(bx+k11,by+k21,bz+k31,ux+k41,uy+k51,uz+k61)
k32 = .5*dt*Eq3(bx+k11,by+k21,bz+k31,ux+k41,uy+k51,uz+k61)
k42 = .5*dt*Eq4(bx+k11,by+k21,bz+k31,ux+k41,uy+k51,uy_1,uy_2,uz+k61)
k52 = .5*dt*Eq5(bx+k11,by+k21,bz+k31,ux+k41,uy+k51,uy_1,uz+k61)
k62 = .5*dt*Eq6(bx+k11,by+k21,bz+k31,ux+k41,uy+k51,uy_1,uz+k61)
k13 = dt*Eq1(bx+k12,by+k22,bz+k32,ux+k42,uy+k52,uz+k62)
k23 = dt*Eq2(bx+k12,by+k22,bz+k32,ux+k42,uy+k52,uz+k62)
k33 = dt*Eq3(bx+k12,by+k22,bz+k32,ux+k42,uy+k52,uz+k62)
k43 = dt*Eq4(bx+k12,by+k22,bz+k32,ux+k42,uy+k52,uy_1,uy_2,uz+k62)
k53 = dt*Eq5(bx+k12,by+k22,bz+k32,ux+k42,uy+k52,uy_1,uz+k62)
k63 = dt*Eq6(bx+k12,by+k22,bz+k32,ux+k42,uy+k52,uy_1,uz+k62)
k14 = dt*Eq1(bx+k13,by+k23,bz+k33,ux+k43,uy+k53,uz+k63)
k24 = dt*Eq2(bx+k13,by+k23,bz+k33,ux+k43,uy+k53,uz+k63)
k34 = dt*Eq3(bx+k13,by+k23,bz+k33,ux+k43,uy+k53,uz+k63)
k44 = dt*Eq4(bx+k13,by+k23,bz+k33,ux+k43,uy+k53,uy_1,uy_2,uz+k63)
k54 = dt*Eq5(bx+k13,by+k23,bz+k33,ux+k43,uy+k53,uy_1,uz+k63)
k64 = dt*Eq6(bx+k13,by+k23,bz+k33,ux+k43,uy+k53,uy_1,uz+k63)
bx = bx + k11/6. + k12/3. + k13/3. + k14/6.
by = by + k21/6. + k22/3. + k23/3. + k24/6.
bz = bz + k31/6. + k32/3. + k33/3. + k34/6.
ux = ux + k41/6. + k42/3. + k43/3. + k44/6.
uy = uy + k51/6. + k52/3. + k53/3. + k54/6.
uz = uz + k61/6. + k62/3. + k63/3. + k64/6.
end subroutine RK4
I feel that I should be adding K5* to uy_1 and uy_2 during this step, where uy_1 and uy_2 are uy(1) and u_y(0) for the purposes of calculating derivatives.
I can elaborate on specifics more at request.
Does anyone have any suggestions/advice?