Particle rotation in galaxy - runge kutta 2nd order help

AI Thread Summary
The discussion revolves around implementing a second-order Runge-Kutta method to model the motion of gas clouds in a spiral galaxy simulation. The user has successfully calculated gravitational acceleration and generated a galaxy rotation curve but is struggling to apply the RK2 method for particle movement. They seek guidance on integrating the appropriate function for the clouds' motion and whether to repeatedly call the gravitational acceleration subroutine. The user expresses frustration with the transition from theoretical physics to practical coding in unfamiliar programming languages. Assistance is requested to overcome the mental block in implementing the RK2 method effectively.
InuYasha
Messages
3
Reaction score
0

Homework Statement


Hi everyone,
I'm a bit stuck and have been staring at my fortran code all day. For my project this year I'm writing a program to model a spiral galaxy in which gas clouds circulate, collide and produce star formation. I've written code for gravitational acceleration due to the disk, halo, bulge and spiral arms. So I have gaccel(x,y,z). I was then able to produce a plot showing the correct galaxy rotation curve using the code below. p_TOT = total gas clouds, factor was an adjustment to get km/s

I now want to make the clouds move using a runge kutta 2nd order method like below. I wrote an RK2 program to solve an ODE as practice and it worked ok (though the method is slightly different from the one I've been asked to implement). I've got a mental block on how to implement RK2 to make the clouds go round the galaxy. Am I being a bit dumb and missing something obvious :-/
Any help would be really appreciated.
Thanks.


Homework Equations



a(n) = a(r(n))
r(n+1/2) = r(n) + v(n)*tstep/2
v(n+1/2) = v(n) + a*tstep/2
a(n+1/2) = a(r(n+1/2)
r(n+1) = r(n) + v(n+1/2)*tstep
v(n+1) = v(n) +a(n+1/2)*tstep
t(n+1) = t(n) +tstep

The Attempt at a Solution


Code:
DO p=1,p_TOT                                      ! loop over particles
    r_MAG=SQRT(r(1,p)**2+r(2,p)**2+r(3,p)**2)     ! compute distance from centre
    a_MAG=SQRT(a(1,p)**2+a(2,p)**2+a(3,p)**2)     ! compute magnitude of acceleration
    v(1,p)=+a(2,p)                                ! compute x-component of velocity
    v(2,p)=-a(1,p)                                ! compute y-component of velocity
    v(3,p)=0.                                     ! set z-component of velocity to zero
    v(1:3,p)=v(1:3,p)*SQRT(r_MAG/a_MAG)           ! scale velocity to centrifugal balance
    v_MAG=SQRT(v(1,p)**2+v(2,p)**2+v(3,p)**2)     ! compute magnitude of velocity
    x(p)=r_MAG                                    ! compute abscissa of plotted point
    y(p)=factor*v_MAG                             ! compute ordinate of plotted point
ENDDO                                             ! end loop over particles

Code:
PROGRAM RK2
IMPLICIT NONE

REAL(kind=8) :: t=0.0,h=0.1
INTEGER :: i, tmax=30
REAL(kind=8),DIMENSION(30) :: y
y(1)=5
DO i=1, tmax
    CALL RUNGEKUTTA(t,y,h,i)
    t=i*h
    WRITE (*,*) "y=",y(i+1)
ENDDO

END PROGRAM RK2

SUBROUTINE RUNGEKUTTA(t,y,h,i)
IMPLICIT NONE
INTEGER :: i
REAL(kind=8) :: t,k1,k2,h
REAL(kind=8),DIMENSION(30) :: y
REAL :: EQN
k1=EQN(t,y,i)
k2=EQN(t+h,y+k1*h,i)
y(i+1)=y(i)+0.5*(k1+k2)*h
END SUBROUTINE RUNGEKUTTA

REAL FUNCTION EQN(t,y,i)
IMPLICIT NONE
INTEGER :: i
REAL(kind=8) :: t
REAL(kind=8),DIMENSION(30) :: y
EQN=3*exp(-t)-0.4*y(i)
RETURN
END FUNCTION EQN
 
Physics news on Phys.org
I think what I'm asking is what would the likely function be that I'm integrating?
I'm pretty sure the code regarding scaling the velocity to centrifugal force only gets called once. Would I need to call the subroutine calculating the gravitational accel (I haven't posted this as it's pretty long. It just gives an acceleration value for x,y,z at the end though). That isn't a differential equation though.
It doesn't help that we haven't been exposed to much programming apart from Mathcad and a little Matlab and now in 3rd year physics we're expected to code everything in languages we don't know. Ay carumba.
 
I multiplied the values first without the error limit. Got 19.38. rounded it off to 2 significant figures since the given data has 2 significant figures. So = 19. For error I used the above formula. It comes out about 1.48. Now my question is. Should I write the answer as 19±1.5 (rounding 1.48 to 2 significant figures) OR should I write it as 19±1. So in short, should the error have same number of significant figures as the mean value or should it have the same number of decimal places as...
Thread 'A cylinder connected to a hanging mass'
Let's declare that for the cylinder, mass = M = 10 kg Radius = R = 4 m For the wall and the floor, Friction coeff = ##\mu## = 0.5 For the hanging mass, mass = m = 11 kg First, we divide the force according to their respective plane (x and y thing, correct me if I'm wrong) and according to which, cylinder or the hanging mass, they're working on. Force on the hanging mass $$mg - T = ma$$ Force(Cylinder) on y $$N_f + f_w - Mg = 0$$ Force(Cylinder) on x $$T + f_f - N_w = Ma$$ There's also...

Similar threads

Replies
4
Views
1K
Replies
15
Views
3K
Replies
14
Views
3K
Replies
5
Views
11K
Replies
1
Views
3K
Back
Top