Advertisement
Guest User

Untitled

a guest
Oct 17th, 2018
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. #include "math.h"
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. double f(double x, double y, double yd) {
  7. return (3 * x*yd + 5 * y + x * x*log(x)) / (x*x);
  8. }
  9.  
  10. int writarr11(double *arr) {
  11. for (int i = 0; i < 11; i++)
  12. cout << arr[i] << ' ';
  13. cout << endl;
  14. return 0;
  15. }
  16.  
  17. int writarr11(double *arr, double *arr1) {
  18. for (int i = 0; i < 11; i++)
  19. cout << arr[i] << ' ' << arr1[i] << endl;
  20. cout << endl;
  21. return 0;
  22. }
  23.  
  24. int writarr101(double *arr) {
  25. for (int i = 0; i < 101; i++)
  26. cout << arr[i] << ' ';
  27. cout << endl;
  28. return 0;
  29. }
  30.  
  31. int writarr101(double *arr, double *arr1) {
  32. for (int i = 0; i < 101; i++)
  33. cout << arr[i] << ' ' << arr1[i] << endl;
  34. cout << endl;
  35. return 0;
  36. }
  37.  
  38. int main()
  39. {
  40. //With h1
  41. double h = 0.1;
  42. cout << "With h1" << endl;
  43.  
  44. //Higher order task
  45. double x[11];
  46. double y[11];
  47. double yd[11];
  48. x[0] = 1;
  49. for (int i = 1; i < 11; i++)
  50. x[i] = x[i - 1] + h;
  51. y[0] = 1;
  52. yd[0] = 1;
  53. for (int i = 1; i < 11; i++) {
  54. yd[i] = yd[i - 1] + h * f(x[i - 1], y[i - 1], yd[i - 1]);
  55. y[i] = y[i - 1] + h * yd[i - 1];
  56. }
  57. cout << "Higher order task" << endl;
  58. writarr11(x, y);
  59. //writarr11(y);
  60. //writarr11(yd);
  61.  
  62. cout << endl << endl << endl;
  63.  
  64. //With h2
  65. h = 0.01;
  66. cout << "With h2" << endl;
  67.  
  68. //Higher order task
  69. double xw[101];
  70. double yw[101];
  71. double ydw[101];
  72. xw[0] = 1;
  73. for (int i = 1; i < 101; i++)
  74. xw[i] = xw[i - 1] + h;
  75. yw[0] = 1;
  76. ydw[0] = 1;
  77. for (int i = 1; i < 101; i++) {
  78. ydw[i] = ydw[i - 1] + h * f(xw[i - 1], yw[i - 1], ydw[i - 1]);
  79. yw[i] = yw[i - 1] + h * ydw[i - 1];
  80. }
  81. cout << "Higher order task" << endl;
  82. writarr101(xw, yw);
  83. //writarr101(yw);
  84. //writarr101(ydw);
  85.  
  86. char c;
  87. getchar();
  88. return 0;
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement