Advertisement
Guest User

Untitled

a guest
Apr 20th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1. #include <iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4.  
  5. double F(double x){
  6. return 16*pow(x,5)-3*(x*x)+1;}
  7.  
  8. double FindRoot(double (*f)(double),double a,double b,double eps){
  9. double c;
  10. while(abs(f(b)-f(a))>eps){
  11.  c=(f(b)*a-f(a)*b)/(f(b)-f(a));
  12.  if((f(a)*f(c)) > 0) a=c;
  13.  else b=c;
  14. }
  15. return c;}
  16. int main(){
  17. //Інтервал, похибка і корінь:
  18. double a,b,eps,x;
  19. cout << "interval: ";
  20. cin >> a;
  21. cin >> b;
  22. if(F(a)*F(b) > 0){
  23.  cout << "Wrong interval!\n";
  24.  return 0;}
  25. cout << "error: ";
  26. cin >> eps;
  27. //Розв'язок:
  28. x=FindRoot(F,a,b,eps);
  29. cout << "x = " << x << endl;
  30. return 0;}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement