appendix : electrical  , solve one differential equation , numerical & symbolic,version 1.0
peter.vlasschaert@gmail.com, 06/01/2020

kill(all)$

How to solve: diff(y,x,1)=x-y  with initial condition  : x0,y0
===========================================
===========================================

/* General : symbolic  &  numerical */

f(x,y):=-y+x;
 x0:0;
 y0:1;

  => symbolic 
===========

/* Here is how to solve a differential equation with ode2 */
===========================================

'diff(y, x) =f(x,y);
ode2(%, y, x);
ic1(%, x =x0, y = y0);
factor(solve(%, y))[1]; 
rhs(%)

;

continue plot
-----------------

wxplot2d([%], [x,0,10])$

 => numerical
===========

General : numerical

n:10;  /* numer of points = n+1 /
h:1;    /*  step value */

/* The Runge-Kutta ( = rk)   'Maxima' */
=========================

n:10;
h:1;
load(dynamics)$
sol: rk(f(x,y), y, y0, [x, x0, n, h]);
wxplot2d([discrete, sol])$

/* An implementation of RK4 for one equation */
=====================================
RK4 : Runge Kutta 4

a)  solve RK4
-------------------

 vx: makelist(0, n + 1);   /* reserved array */
 vy: makelist(0, n + 1);  
   x: x0; 
   y: y0;
   vx[1]: x0;
   vy[1]: y0;
   for i from 1 thru n do (
      k1: ev(h * f(x, y),float),
      k2: ev(float(h * f(x + h / 2, y + k1 / 2))),
      k3: ev(float(h * f(x + h / 2, y + k2 / 2))),
      k4: ev(float(h * f(x + h, y + k3))),
      y: y + (k1 + 2 * k2 + 2 * k3 + k4) / 6,
      vy[i + 1]: y,
      x:x+h ,         
      vx[i + 1]: x)$

 vx;

vy;

b) discrete plot: RK4
-----------------------------

v:[]$
for i from 1 thru n+1 do(
v:endcons([vx[i],vy[i]],v))$
v;
wxplot2d([discrete,v])$