1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
#include <math.h>
#include <iostream>
using namespace std;
//Define function f(x)
double f(double x, double a, double b)
{
return sin((a*x)/(1+x*x))*atan(b*x)+atan(x);
}
int main()
{
//Input a,b parameters constants, lower and upper approximation points as well as a precision value N
double a, b, N, lowerB, upperB;
cout <<"Give me a value for constant a: ";
cin >> a;
cout <<"Give me a value for constant b: ";
cin >> b;
cout <<"Give me a precision:";
cin>> N;
cout <<"Give me lower and upper approximations:";
cin>>lowerB >> upperB;
double RootFinderSMNew(double f, double a, double b, double lowerB, double upperB, int N);
{
double f_left=f(lowerB, a, b),now=lowerB+N,f_right=f(now, a, b);
while(f_left*f_right>0 && now<lowerB)
{
f_left=f_right;
now+=N;
f_right=f(now, a, b);
}
return now-N/2;
}
cout << "A root is: "<<
RootFinderSMNew(f,a,b,upperB,lowerB,N) << endl;
return 0;
}
|