0% found this document useful (0 votes)
9 views

Falsi Position Method 1

Uploaded by

Hassan Tahamid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Falsi Position Method 1

Uploaded by

Hassan Tahamid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Falsi Position Method

Derivation:
Main Algorithm:

int main()
{
float x0, x1, x, f0, f1, f, e;
int step = 1;

up:

f0 = f(x0);
f1 = f(x1);

if( f0 * f1 > 0.0)


{
goto up;
}
do
{
x = x0 - (x0-x1) * f0/ (f0-f1);
f = f(x);
if( f0 * f < 0)
{
}
else
{

}
step = step + 1;
}
while(fabs(f)>e);
return 0;
}
Code:

#include<iostream>
#include<iomanip>
#include<math.h>
#define f(x) cos(x) - x * exp(x)

using namespace std;

int main()
{
float x0, x1, x, f0, f1, f, e;
int step = 1;

cout<< setprecision(6)<< fixed;

up:
cout<<"Enter first guess: ";
cin>>x0;
cout<<"Enter second guess: ";
cin>>x1;
cout<<"Enter tolerable error: ";
cin>>e;

f0 = f(x0);
f1 = f(x1);

if( f0 * f1 > 0.0)


{
cout<<"Incorrect Initial Guesses."<< endl;
goto up;
}
cout<< endl<<"*********************"<< endl;
cout<<"False Position Method"<< endl;
cout<<"*********************"<< endl;
do
{
x = x0 - (x0-x1) * f0/ (f0-f1);
f = f(x);

cout<<"Iteration-"<< step<<":\t x = "<< setw(10)<<


x<<" and f(x) = "<< setw(10)<< f(x)<< endl;

if( f0 * f < 0)
{
x1 = x;
f1 = f;
}
else
{
x0 = x;
f0 = f;
}
step = step + 1;
}
while(fabs(f)>e);
cout<< endl<<"Root is: "<< x<< endl;

return 0;
}

Output:

You might also like