0

So I am trying to use runge kutta 4, to more acurately calculate forces. I am using code from github and I used their example of rabits and wolves populations. In IntegratorLSODE.cs, in lotkaVolterra(), that is where the customization happens, like the birth and death rate of each animal.

What I am confused about is the equations to calculate dR and dW.

I feel like I am doing this wrong, because I just set the force through another variable, and this ends up (I think) doing the same thing as in Euler's Method! I believe the problem is that I need to create an equation involving x and/or y. I have no idea how to do this.

Here's my code: (I changed it from the guy on github's)enter image description here Note: To compare code, got to the other guy's code on github.

Q: What can I do to accurately predict forces (runge kutta) without just using euler's method?

gbe
  • 207
  • 1
    What do you mean with "predict forces"? Usually the force is a function of position and velocity that is determined by the model you are examining. In your code, force is an unchanging constant. // If you add a third state component, then it is always associated with the index 2. // All Runge-Heun-Kutta methods are expansions on the idea of the Euler method, there is no surprise that they have structural similarities. – Lutz Lehmann Aug 07 '22 at 06:21
  • @lutz lehmann By predict forces, I mean, say I had a vector of 3 numbers, x, y, z. I try to add force by adding x, y, z to it. – gbe Aug 07 '22 at 16:55
  • 1
    It still makes no sence, force.x etc. are just the fields/members/component of the vector3d object force. I think this parameter was intended to be used as control or auxiliary input, it is never changed in the visible code. // The time loop is wrong or extremely inefficient, this is unchanged from the github code. – Lutz Lehmann Aug 07 '22 at 17:09
  • oh, I see what you mean, the force has to be the output? So, no third parameter? If I do this, will it fully work? – gbe Aug 07 '22 at 17:42
  • I have a force vector, and then I have a position vector. I add the force to the position, so I thought I would pass it through?? Am I wrong? – gbe Aug 07 '22 at 17:46
  • 1
    As long as the addressee is unique, you do not need to ping. It would help if you formulated the ODE you want to solve in formulas. For a mechanical model $m\ddot q=F(t,q,\dot q)$, $q=(x,y,z)$, the first-order system has a 6-dimensional state vector containing position and velocity coordinates. See https://math.stackexchange.com/questions/4176684/how-to-implement-a-runge-kutta-method-rk4-for-a-second-order-differential-equa for mostly python examples, but the logic should be recognizable. – Lutz Lehmann Aug 07 '22 at 18:21
  • I am just confused about what equation i should use to calculate "ret" in lotkaVolterra(), thanks – gbe Aug 07 '22 at 18:44
  • 1
    You put there the derivatives vector of the model you want to simulate. What that system is you need to know yourself, there has to be a reason that you expanded to 3 dimensions. – Lutz Lehmann Aug 07 '22 at 19:21
  • okay thank you. – gbe Aug 07 '22 at 19:26

0 Answers0