Advertisement
kachamaka

ЧА-6

Nov 15th, 2022 (edited)
311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. f1[t_] := 1/(1 + t);
  2. f2[t_] := 1/(2 + t);
  3. f3[t_] := 1/(3 + t);
  4. f[t_] := Exp[-t];
  5. s1 = Solve[{a*f1[1] + b*f2[1] + c*f3[1] == f[1],
  6. a*f1[2] + b*f2[2] + c*f3[2] == f[2],
  7. a*f1[3] + b*f2[3] + c*f3[3] == f[3]}, {a, b, c}]
  8. L[t_] := Simplify[a*f1[t] + b*f2[t] + c*f3[t] /. s1];
  9. L[t]
  10. Plot[f[t] - L[t], {t, 1, 3}]
  11.  
  12.  
  13.  
  14. n = 5;
  15. f[t_] := Sqrt[t];
  16. Do[x[k] = k/n, {k, 0, n}];
  17. Do[c[k] = ((f[x[k + 1]] - f[x[k]])/(x[k + 1] - x[k]) - (f[x[k]] -
  18. f[x[k - 1]])/(x[k] - x[k - 1]))/2, {k, 1, n - 1}];
  19. c[0] = ((f[x[0]] + f[x[n]])/(x[n] - x[0]) + (f[x[1]] -
  20. f[x[0]])/(x[1] - x[0]))/2;
  21. c[n] = ((f[x[0]] + f[x[n]])/(x[n] - x[0]) - (f[x[n]] -
  22. f[x[n - 1]])/(x[n] - x[n - 1]))/2;
  23. I1[t_] := Sum[c[k]*Abs[t - x[k]], {k, 0, n}];
  24. Plot[f[t] - I1[t], {t, 0, 1}, PlotRange -> All]
  25. Plot[{f[t], I1[t]}, {t, 0, 1}]
  26.  
  27. n = 50;
  28. f[t_] := Sqrt[t];
  29. Do[x[k] = k/n, {k, 0, n}];
  30. Do[c[k] = ((f[x[k + 1]] - f[x[k]])/(x[k + 1] - x[k]) - (f[x[k]] -
  31. f[x[k - 1]])/(x[k] - x[k - 1]))/2, {k, 1, n - 1}];
  32. c[0] = ((f[x[0]] + f[x[n]])/(x[n] - x[0]) + (f[x[1]] -
  33. f[x[0]])/(x[1] - x[0]))/2;
  34. c[n] = ((f[x[0]] + f[x[n]])/(x[n] - x[0]) - (f[x[n]] -
  35. f[x[n - 1]])/(x[n] - x[n - 1]))/2;
  36. I1[t_] := Sum[c[k]*Abs[t - x[k]], {k, 0, n}];
  37. Plot[f[t] - I1[t], {t, 0, 1}, PlotRange -> All]
  38. Plot[{f[t], I1[t]}, {t, 0, 1}]
  39.  
  40.  
  41. n = 50;
  42. f[t_] := Sqrt[t];
  43. Do[x[k] = (k/n)^4, {k, 0, n}];
  44. Do[c[k] = ((f[x[k + 1]] - f[x[k]])/(x[k + 1] - x[k]) - (f[x[k]] -
  45. f[x[k - 1]])/(x[k] - x[k - 1]))/2, {k, 1, n - 1}];
  46. c[0] = ((f[x[0]] + f[x[n]])/(x[n] - x[0]) + (f[x[1]] -
  47. f[x[0]])/(x[1] - x[0]))/2;
  48. c[n] = ((f[x[0]] + f[x[n]])/(x[n] - x[0]) - (f[x[n]] -
  49. f[x[n - 1]])/(x[n] - x[n - 1]))/2;
  50. I1[t_] := Sum[c[k]*Abs[t - x[k]], {k, 0, n}];
  51. Plot[f[t] - I1[t], {t, 0, 1}, PlotRange -> All]
  52. Plot[{f[t], I1[t]}, {t, 0, 1}]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement