Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. using namespace std;
  2.  
  3. double f(double x)
  4. {
  5. return exp(x)*sin(2 * x);
  6. }
  7.  
  8. double xi(double x, int i, double h)
  9. {
  10. return x + i * h;
  11. }
  12.  
  13. double FPrimRSP(double x, double h)
  14. {
  15. return (-1 * f(xi(x, 2, h)) + 4 * f(xi(x, 1, h)) - 3 * f(x)) / (2 * h);
  16. }
  17.  
  18. double FBisRSP(double x, double h)
  19. {
  20. return (-1 * f(xi(x, 3, h)) + 4 * f(xi(x, 2, h)) - 5 * f(xi(x, 1, h)) + 2 * f(x)) / pow(h, 2);
  21. }
  22.  
  23. double FTerRSP(double x, double h)
  24. {
  25. return (-3 * f(xi(x, 4, h)) + 14 * f(xi(x, 3, h)) - 24 * f(xi(x, 2, h)) + 18 * f(xi(x, 1, h)) - 5 * f(x)) / (2 * pow(h, 3));
  26. }
  27.  
  28. double FPrimRST(double x, double h)
  29. {
  30. return (3 * f(x) - 4 * f(xi(x, -1, h)) + f(xi(x, -2, h))) / (2 * h);
  31. }
  32.  
  33. double FBisRST(double x, double h)
  34. {
  35. return (2 * f(x) - 5 * f(xi(x, -1, h)) + 4 * f(xi(x, -2, h)) - f(xi(x, -3, h))) / pow(h, 2);
  36. }
  37.  
  38. double FTerRST(double x, double h)
  39. {
  40. return (5 * f(x) - 18 * f(xi(x, -1, h)) + 24 * f(xi(x, -2, h)) - 14 * f(xi(x, -3, h)) + 3 * f(xi(x, -4, h))) / (2 * pow(h, 3));
  41. }
  42.  
  43. double FPrimRSC(double x, double h)
  44. {
  45. return (f(xi(x, 1, h)) - f(xi(x, -1, h))) / (2 * h);
  46. }
  47.  
  48. double FBisRSC(double x, double h)
  49. {
  50. return (f(xi(x, 1, h)) - 2 * f(x) + f(xi(x, -1, h))) / (pow(h, 2));
  51. }
  52.  
  53. double FTerRSC(double x, double h)
  54. {
  55. return (f(xi(x, 2, h)) - 2 * f(xi(x, 1, h)) + 2 * f(xi(x, -1, h)) - f(xi(x, -2, h))) / (2 * pow(h, 3));
  56. }
  57.  
  58. int main()
  59. {
  60. double h = 1.e-4;
  61. double x;
  62. cout << "Podaj x: " << endl;
  63. cin >> x;
  64. cout << "RSP" << endl;
  65. cout << "F'(" << x << ")" << "\t" << FPrimRSP(x, h) << endl;
  66. cout << "F''(" << x << ")" << "\t" << FBisRSP(x, h) << endl;
  67. cout << "F'''(" << x << ")" << "\t" << FTerRSP(x, h) << endl;
  68. cout << "RST" << endl;
  69. cout << "F'(" << x << ")" << "\t" << FPrimRST(x, h) << endl;
  70. cout << "F''(" << x << ")" << "\t" << FBisRST(x, h) << endl;
  71. cout << "F'''(" << x << ")" << "\t" << FTerRST(x, h) << endl;
  72. cout << "RSC" << endl;
  73. cout << "F'(" << x << ")" << "\t" << FPrimRSC(x, h) << endl;
  74. cout << "F''(" << x << ")" << "\t" << FBisRSC(x, h) << endl;
  75. cout << "F'''(" << x << ")" << "\t" << FTerRSC(x, h) << endl;
  76.  
  77. return 0;
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement