Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 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. double suma = 1.0;
  35. double silnia = 1.0;
  36. double potega = 1.0;
  37.  
  38. for (int i = 1; i <= n; ++i)
  39. {
  40. silnia *= i;
  41. potega *= x;
  42. suma += potega / silnia;
  43. }
  44. return suma;
  45. }
  46.  
  47.  
  48.  
  49. int main()
  50. {
  51. int i = 0;
  52. ifstream plik;
  53. plik.open("plik.txt");
  54.  
  55. while (!plik.eof())
  56. {
  57. plik >> tab1[i] >> tab2[i] >> tab3[i];
  58. i++;
  59. }
  60.  
  61. for (i = 0; i < 3900; i++)
  62. {
  63. blad(tab2[i], tab3[i], i);
  64. tab6[i] = ((1 - szeregTaylora(-tab2[i], 100)) / tab2[i]);
  65. bladTaylor(tab6[i], tab3[i], i);
  66. }
  67. cout << " x | Wd | Wp | Blad wzgledny | Taylor | Blad wzgledny(Taylor)" << endl;
  68. cout << "------------------------------------------------------------------------------------------------------------------------------------------------------------" << endl;
  69. for (i = 0; i < 3900; i++)
  70. {
  71.  
  72. cout.width(7);
  73. cout << tab2[i];
  74. cout.width(14);
  75. cout << tab3[i];
  76. cout.width(21);
  77. cout << tab5[i];
  78. cout.width(28);
  79. cout << tab4[i];
  80. cout.width(35);
  81. cout << tab6[i];
  82. cout.width(42);
  83. cout << tab7[i] << endl;
  84. cout << endl;
  85. }
  86.  
  87. system("Pause");
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement