Advertisement
Guest User

Untitled

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