SHARE
TWEET

Untitled

a guest Nov 19th, 2019 91 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <math.h>
  3. #include<cmath>
  4. using namespace std;
  5.  
  6. double f(double x) // funkcja do testowania (H)
  7. {
  8.     return (2 * exp(-x) - sqrt(exp(x)) - 1);
  9.     //return pow(5,x) - x - 3; // wzor A, z nim funkcja dziala bez problemu
  10. }
  11.  
  12. double fp(double x) //pochodna
  13. {
  14.     return (-0.5 * exp(-x) * (pow(exp(x),3/2) + 4));
  15.     //return pow(5,x) * log(5) - 1; //pochodna A
  16. }
  17.  
  18. double u(double x) //funkcja pomocnicza do formuly wielopunktowej
  19. {
  20.     return f(x)/fp(x);
  21. }
  22.  
  23. double formula(double x) //formula numer 5
  24. {
  25.     return x - (u(x) / (2 * fp(x))) * (3 * fp(x) - fp(x - u(x)));
  26. }
  27.  
  28. void Newton() //w zaleznosci od badanego kryterium zmienic petle zeby dawala kolejne epsilony zamiast x
  29. {
  30.     double h, x = -20;
  31.     const double epsilon = pow(10, -8);
  32.     int k = 0;
  33.  
  34.         do
  35.         {
  36.             h = -(f(x) / fp(x));
  37.             k++;
  38.             x += h;
  39.         }while(fabs(h) >= epsilon);
  40.  
  41.         cout << endl << "wynik: " << x << endl << "Liczba ruchow: " << k << endl;
  42. }
  43.  
  44. void wielopunktowa()
  45. {
  46.  
  47.     double h, x = 0.000002;
  48.     const double epsilon = 1e-8;
  49.     int k = 0;
  50.  
  51.         do
  52.         {
  53.             h = formula(x);
  54.             k++;
  55.             x += h;
  56.         }while(fabs(h) >= epsilon);
  57.  
  58.         cout << endl << "wynik: " << x << endl << "Liczba ruchow: " << k << endl;
  59.  
  60. }
  61.  
  62. int main()
  63. {
  64.     cout.precision(16);
  65.  
  66.     wielopunktowa();
  67.     return 0;
  68. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top