Advertisement
Guest User

Untitled

a guest
Dec 14th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. n = 4;
  2. f[t_] := E^(-5*t);
  3. x[0] = x[1] = x[2] = 0;
  4. x[3] = x[4] = 1;
  5. DividedDifferences[f_, from_, to_] := If[from == to, f[x[from]],
  6.  
  7. If[x[from] ==
  8. x[to], (D[f[t], {t, to - from}] /. t -> x[from])/(to - from)!,
  9. (DividedDifferences[f, from + 1, to] -
  10. DividedDifferences[f, from, to - 1])/(x[to] - x[from])]];
  11. myProduct[t_, to_] := Product[t - x[k], {k, 0, to - 1}];
  12. myPolynomial[f_] :=
  13. Sum[DividedDifferences[f, 0, k]*myProduct[x, k], {k, 0, n}];
  14. p = N[Expand[myPolynomial[f]]]
  15. Plot[Abs[f[x] - p], {x, 0, 1}, PlotRange -> All]
  16.  
  17. +++++++++++++++++++++++++++++++++++++++++++++++++++++++
  18.  
  19. f[t_] := E^(-5*t);
  20. InterpolatingPolynomial[{{0, {1, -5, 25}}, {1, {E^(-5), -5 E^(-5)}}},
  21. x];
  22. N[Expand[%]]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement