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$

Logging:false;

print("Eulix errors:")$
ER: Eulix([-2*t*y^2],[y],[1/(1+alpha)],[t,1,-1,-0.1],logging=Logging)$
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))))
);

printf(true,"~%~%--------- search for y=8 ---------~%~%")$
[Root_at,eusol]: Eulix([-2*t*y^2],[y],[1/(1+alpha)],[t,1,-1,-0.1,y-8],logging=Logging)$
if first(Root_at) > 0 then
  print("root at ",second(Root_at),"   triggered by condition ",first(Root_at),
        "root solution=
",third(Root_at))
  else (
  print("no root condition was triggered"),
  [tlist,ylist]:eusol,
  print("Final Solution=
  ", ylist[length(tlist)])
  )$


