Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // CMEP Lab No 2
- // False Position Method
- // 16 march 2020
- // Mohsin Riad
- #include<bits/stdc++.h>
- using namespace std;
- double func(double x)
- {
- return (x*x*x-x*x-2*x-1);
- }
- double false_pos(double a, double b)
- {
- double pv = -1,xm;
- double xl =a, xh=b;
- // int mx=1000;
- while(1)
- {
- xm = (xh*func(xl)-xl*func(xh))/(func(xl)-func(xh));
- if(pv == xm || func(xm) ==0) break;
- else pv = xm;
- if(func(xl)*func(xm) , 0) xh=xm;
- else
- xl=xm;
- //cout<<fixed;
- //cout<<setprecision(16);
- //cout<<"pre root: "<<xm<<endl;
- }
- return xm;
- }
- int main()
- {
- double a,b;
- cin>>a>>b;
- cout<<"\n Final Root: "<<false_pos(a,b)<<endl;
- return 0;
- }
- /* Input:
- 2 3
- Output:
- Final root : 2.1479
- /*
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement