I am trying to implement Runge-Kutta's 4th order integration method in matlab on a 2-d matrix (x, y). The matrix contains a height value (float) at each point. The idea is place a particle in the matrix and watch it's path as it gets 'pushed' around by the directional vectors u and v.
I have implemented Euler's integration method already using simply the 'gradient' function built in matlab. However, for RK4 integration, I need to take 4 slopes at variable points, not the predetermined slope given by the gradient.
I think the Matlab gradient function itself doesn't have these kind of parameters (from what I understand from the Matlab docs). What kind of approach should I take for this?
If I were to write my own gradient function that computes the slope at any arbitrary point, I am not quite sure how to write it, since it is not a straight-foward function. Are there any suggestions for this approach?
Thanks.