interpol.red 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. module interpol; % polynomial interpolation (Aitken & Neville).
  2. % Author: Herbert Melenk <melenk@sc.zib-berlin.de>.
  3. symbolic procedure interpol(fc,x,pts);
  4. % find a polynomial f(x) such that holds:
  5. % f(part(pts,i)) = part(fc,i) for all i <= lenth pts.
  6. % The Aitken-Neville schema is used; it is stable for
  7. % symbolic and numeric values.
  8. begin scalar d,q,s,p1,p2,x1,x2,f1,f2,fnew;
  9. if not eqcar(fc,'list) or not eqcar(pts,'list)
  10. or not(length fc=length pts)
  11. then rerror(poly,19,"Illegal parameters for interpol");
  12. s:=for each p in pair(cdr fc,cdr pts) collect
  13. simp car p . simp cdr p . simp cdr p;
  14. x:= simp x;
  15. % outer loop as long as there is more than 1 element.
  16. while cdr s do
  17. <<q:= nil;
  18. % inner loop for all adjacent pairs of polynomials.
  19. while cdr s do
  20. <<p1:=car s; s:=cdr s; p2:=car s;
  21. f1:=car p1; f2:=car p2; x1:=cadr p1; x2:=cddr p2;
  22. d:=subtrsq(x1,x2);
  23. if null numr d then rerror(poly,20,
  24. "Interpolation impossible if two points are equal");
  25. fnew:=
  26. quotsq(
  27. subtrsq(multsq(subtrsq(x,x2),f1),
  28. multsq(subtrsq(x,x1),f2)),
  29. d);
  30. q:=(fnew.x1.x2).q;
  31. >>;
  32. s:=reversip q;
  33. >>;
  34. return prepsq caar s;
  35. end;
  36. % We can't do following for bootstrapping reasons.
  37. % symbolic operator interpol;
  38. flag('(interpol),'opfn);
  39. endmodule;
  40. end;