0

I am tried to solve a stochastic differential equation. After running my code for the 10th times I got this error, which I cannot address. Some help would be nice:

ux = np.zeros(N+1)
uy = np.zeros(N+1)
t = np.zeros(N+1)

def f(u1, u2, t, alpha):
    return -alpha * u1* (1-1/(np.sqrt(u1**2+u2**2)))


def ForwardEuler_iso(f, nin, nfin, dt, ux, uy, t):
    for k in range(nin+1, nfin):
        t[k+1]=t[k]+dt
        ux[k+1]=ux[k]+dt*f(ux[k], uy[k], t, alpha)+k_delta*np.sqrt(dt)*np.random.randn()
        uy[k+1]=uy[k]+dt*f(uy[k], ux[k], t, alpha)+k_delta*np.sqrt(dt)*np.random.randn()
    return ux, uy, t

ux, uy, t = ForwardEuler_iso(f_pol, N_pol+1, N, dt, ux, uy, t)

The error is given on ux, uy, t....

  • Can you provide a full working code to reproduce the problem? Lots of variables missing. – Peter Meisrimel Nov 22 '20 at 20:55
  • 1
    A full traceback might also help. My guess is that one of the `var[i]=...` expressions is trying to assign an array (multiplie values) to one element of an array. You need to identify which assign is the problem, and why – hpaulj Nov 22 '20 at 21:21
  • Is it intentional that the stochastic increments are independent? Is the definition of `f` actually the definition of `f_pol`? In your call `f(ux[k], uy[k], t, alpha)` you are passing the whole time array. Probably you only want to pass `t[k]`. But as `t` is not used in that `f`, this can not be the error. Or did you switch to a function where the time argument was used? – Lutz Lehmann Nov 22 '20 at 22:22

0 Answers0