Talk:Euler–Maruyama method

Range of the index of Yn
In the line

"recursively define Yn for 1 ≤ n ≤ N"

shouldn't the index be 0 ≤ n ≤ N-1?

Otherwise Y1 will not be computed, since Yn + 1 = Y2 for n = 1.

Moreover, the last value to be computed will be YN+1, which is outside the interval of time [0, T] partitioned by 𝞃0 < 𝞃1 < ... < 𝞃N. — Preceding unsigned comment added by Rabelais (talk • contribs) 16:49, 29 February 2020 (UTC)

Wrong time partition in the example implementations
In both Python and Matlab codes, Δt is defined as

which, referring to the theoretical definition, implies a partition of [t_init t_end] in N+1 points.

But the partition is defined as

which is a vector of N elements (should be N+1) given by [t_init, t_init+dt, t_init+2*dt, ..., t_end-dt], hence it does not contain the final time;

which is a vector of N elements (should be N+1) given by [t_init, t_end/(N-1), 2*t_end/(N-1), ..., t_end], so it is a totally different time partition (excluding the extremes), even though, by the numerical point of view, it is not important what the partition contains but the number of the elements contained.

Then, the internal 'for' cycle devoted to the computation of the approximations is defined as

hence 'i' goes from 1 to N-1 (should be from 1 to N) and the approximation corresponding to t_end is not computed;

hence 'i' goes from 2 to N (should be from 2 to N+1) and the approximation corresponding to t_end is not computed.

The theoretical definition states that


 * the time interval [t_init, t_end] is partitioned in N interval, i.e. in N+1 nodes


 * the length of each subinterval is t_end/N


 * an approximation for each node has to be computed, hence a total of N+1 approximations have to be computed (the first approximation Y_0 is given by the initial condition)

So either Δt should be changed to

or ts should be changed to

and to


 * In the python code, the relation 'assert len(TS) == TS.size == N + 1' holds true and a for-loop starts at 0. I made everything explicit in the code now, with an assert. I.e. the python code uses a grid of 1001 points and does 1000 computations (as opposed to having a grid of 1000). I didn't touch the Matlab code, but I think it's fairly clear.
 * 91.141.56.40 (talk) 18:36, 11 January 2023 (UTC)