Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include<cstdlib>
- using namespace std;
- double F(double x){
- return 16*pow(x,5)-3*(x*x)+1;}
- double FindRoot(double (*f)(double),double a,double b,double eps){
- double c;
- while(abs(f(b)-f(a))>eps){
- c=(f(b)*a-f(a)*b)/(f(b)-f(a));
- if((f(a)*f(c)) > 0) a=c;
- else b=c;
- }
- return c;}
- int main(){
- //Інтервал, похибка і корінь:
- double a,b,eps,x;
- cout << "interval: ";
- cin >> a;
- cin >> b;
- if(F(a)*F(b) > 0){
- cout << "Wrong interval!\n";
- return 0;}
- cout << "error: ";
- cin >> eps;
- //Розв'язок:
- x=FindRoot(F,a,b,eps);
- cout << "x = " << x << endl;
- return 0;}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement