3

According to what I have read, the first formula is the classical Euler method and the second is the improved Euler method for second-order equations.

  • Method A: accuracy of order h
S[a_, b_, h_, N_] := (u[0] = a; u[1] = a + h*b; 
  Do[u[n + 1] = 
    2 u[n] - u[n - 1] + h*h*f[n*h, u[n], (u[n] - u[n - 1])/h], {n, 1, 
    N}])
  • Method B: accuracy of order h^2
Q[a_, b_, h_, N_] := (u[0] = a; v[0] = b; 
  Do[{u[n + 1] = 
     u[n] + h*
       F[u[n] + (h/2)*F[u[n], v[n]], 
        v[n] + (h/2)*
          G[u[n], v[
            n]]],                                                     \
v[n + 1] = 
 v[n] + h*
   G[u[n] + (h/2)*F[u[n], v[n]], v[n] + (h/2)*G[u[n], v[n]]]}, {n,
 0, N}])

All the examples I have seen both in the book I have and in YouTube videos deal with two function systems and initial values. My question is this if we are given more than two functions how should we work? I can't find an example guide to figure out how. Any example would be appreciated. Thank you in advance

For example

It is given the following problem: $$X'=Z+(Y-\alpha)X$$ $$Y'=1-\beta Y-X^2$$ $$Z'=-X-\gamma Z$$ with initial conditions $(X(0),Y(0),Z(0)=(1,2,3)$.

Where

X: interest rate

Υ:investment demand

Z: price index

$\alpha$: savings, $\beta$: cost per investment, $\gamma$: the absolute value of the elasticity of demand

And we want the results with the Improved Eulers method. It is obvious that I have to use Method B: accuracy of order h^2. But I do not know how to define the new function on Mathematica

  • 2
    To me, this sounds more of a Mathematics Question, appropriate for Math SE. – Domen Jan 26 '23 at 23:46
  • @Domen Fyi I have updated my post so you will understand what I mean – Athanasios Paraskevopoulos Jan 26 '23 at 23:56
  • @cvgmt I created a new question about Improved Eulers Method as we discussed earlier today. – Athanasios Paraskevopoulos Jan 27 '23 at 00:27
  • 1st implementation you've found is bounded on second order equations i.e. equation in form $y′′=f(x,y,y′)$ so it cannot be extended to first order system i.e. $y′=f(x,y)$, at least cannot be extended in a straightforward way. 2. Euler's method can be defined based on first order system in a much simpler manner, and n-th order system can always be transformed to 1st order system, see e.g. https://mathematica.stackexchange.com/a/158519/1871, notice 2nd implementation you've found is essentially based on this idea. BTW…
  • – xzczd Jan 27 '23 at 02:59
  • …it's usually called midpoint method: https://en.wikipedia.org/wiki/Midpoint_method 3. 2nd implementation you've found isn't convenient for extending, to implement it in a more convenient way, observe the output of Sin[{Pi/3, Pi/6}] and think about how you can make use of this feature of Mathematica. 4. Please first make some effort to understand Euler's method itself, the wiki page isn't a bad source: https://en.wikipedia.org/wiki/Euler_method – xzczd Jan 27 '23 at 03:07
  • Why do you add the last code sample involving NDSolve to your question? It's not related to the implementation of Euler method at all. 6. You should add PlotPoints -> 500 to ParametricPlot3D.
  • – xzczd Jan 27 '23 at 08:35
  • I have read the https://reference.wolfram.com/language/tutorial/NDSolveExplicitRungeKutta.html and i tried to do the same for Euler's Method – Athanasios Paraskevopoulos Jan 27 '23 at 08:38
  • You haven't done the same. The built-in ExplicitEuler is a variable-step method. Please read the Step Control section carefully. See also the document for FixedStep method. – xzczd Jan 27 '23 at 09:13