Advertisement
Guest User

Untitled

a guest
Mar 27th, 2017
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. // ConsoleApplication4.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6. #include <fstream>
  7.  
  8. using namespace std;
  9.  
  10. double tab1[3900] = { 0 }; // log(x)
  11. double tab2[3900] = { 0 }; // x
  12. double tab3[3900] = { 0 }; // wd
  13. double tab4[3900] = { 0 }; // blad wzgledny
  14. double tab5[3900] = { 0 }; // wartos przyblizona
  15. double tab6[3900] = { 0 }; // f(x) taylorem
  16. double tab7[3900] = { 0 }; //blad wzgledny(taylor)
  17.  
  18. void blad(double x, double wd, int i)
  19. {
  20. double wp,blad;
  21. wp = (1 - exp(-x))/x;
  22. blad = abs((wp - wd )/ wd);
  23. tab4[i] = blad;
  24. tab5[i] = wp;
  25. }
  26.  
  27. void bladTaylor(double tab6, double wd, int i)
  28. {
  29. tab7[i] = abs((tab6 - wd) / wd);
  30. }
  31.  
  32. double szeregTaylora(double x, int n) {
  33.  
  34.  
  35. double suma = 1.0;
  36. double silnia = 1.0;
  37. double potega = 1.0;
  38.  
  39. if (x >= 0)
  40. {
  41. for (int i = 1; i <= n; ++i)
  42. {
  43. silnia *= i;
  44. potega *= x;
  45. suma += potega / silnia;
  46. }
  47. return suma;
  48. }
  49. else
  50. return 1 / szeregTaylora(-x, n);
  51. }
  52.  
  53.  
  54.  
  55. int main()
  56. {
  57. int i = 0;
  58. ifstream plik;
  59. plik.open("plik.txt");
  60.  
  61. while (!plik.eof())
  62. {
  63. plik >> tab1[i] >> tab2[i] >> tab3[i];
  64. i++;
  65. }
  66.  
  67. for (i = 0; i < 3900; i++)
  68. {
  69. blad(tab2[i], tab3[i], i);
  70. tab6[i] = ((1 - szeregTaylora(-tab2[i], 100)) / tab2[i]);
  71. bladTaylor(tab6[i], tab3[i], i);
  72. }
  73. cout << " x | Wd | Wp | Blad wzgledny | Taylor | Blad wzgledny(Taylor)" << endl;
  74. cout << "------------------------------------------------------------------------------------------------------------------------------------------------------------" << endl;
  75. for (i = 0; i < 3900; i++)
  76. {
  77.  
  78. cout.width(7);
  79. cout << tab2[i];
  80. cout.width(14);
  81. cout << tab3[i];
  82. cout.width(21);
  83. cout << tab5[i];
  84. cout.width(28);
  85. cout << tab4[i];
  86. cout.width(35);
  87. cout << tab6[i];
  88. cout.width(42);
  89. cout << tab7[i] << endl;
  90. cout << endl;
  91. }
  92.  
  93. system("Pause");
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement