load("Eulix.mac")$

/* This is a 1-d example
   For small (positive) alpha, the solution is very sensitive to errors
   in the initial value or discetization errors.
   It has a peek at t=0 : (1/alpha)^2 and it is stiff near t = 0 (lambda=-2*t/alpha^2)
   y'(t)= -2*t*y(t)^2      y(-1)= 1/(1+alpha)   e.g. alpha= 0.1
*/

debugmode:true$
solution(t,t0,y0):= block([C:1/y0-t0*t0],1/(t^2+C));
alpha:0.1$
timer(Eulix)$
/*  rkf45 is broken for t_end < t_start
load("rkf45.mac")$
timer(rkf45,Eulix)$

print("rkf45 errors:")$
RR:rkf45(-2*t*y^2,y,1/(1+alpha),[t,1,-1])$
for i:1 thru length(RR) do block([ty:RR[i],t,y],
  t:first(ty),y:second(ty),
  printf(true,"at t= ~7,4f  err= ~10,3e~%",t,(y-solution(t,1,1/(1+alpha))))
);
*/

print("Eulix errors:")$
ER: Eulix([-2*t*y^2],[y],[1/(1+alpha)],[t,1,-1])$
for i:1 thru length(ER) do block([ty:ER[i],t,y],
  t:first(ty),y:second(ty),
  printf(true,"at t= ~7,4f  err= ~10,3e~%",t,(y-solution(t,1,1/(1+alpha))))
);
timer_info();  /* Eulix: 0.905 sec */


