Skip to content

Instantly share code, notes, and snippets.

@prodhan
Created March 8, 2019 18:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prodhan/99fcd2f14055ec831045343ce3e7a864 to your computer and use it in GitHub Desktop.
Save prodhan/99fcd2f14055ec831045343ce3e7a864 to your computer and use it in GitHub Desktop.
Problem No 22 using False Position
/*
Created By Ariful Islam
Batch E-64 (DIU)
Roll: 34
problem no 22
EQN: x=cubic root (48)
Method: False Position
Note: Root lies between 3 and 4
*/
#include<iostream>
#include <math.h>
using namespace std;
double func(double x)
{
return x-cbrt(48);
}
void regulaFalsi(double a, double b, int itr)
{
if (func(a) * func(b) >= 0)
{
cout << "You have not assumed right a and b\n";
return;
}
double c = a;
for (int i=0; i < itr; i++)
{
c = (a*func(b) - b*func(a))/ (func(b) - func(a));
cout<<"f(xi) = "<<func(c)<<endl;
if (func(c)==0)
break;
else if (func(c)*func(a) < 0)
b = c;
else
a = c;
}
cout << "The value of root is : " << c;
}
int main()
{
double a, b;
int itr;
cout<<"Enter the real value for constant 'a': ";
cin>>a;
cout<<"Enter the real value for constant 'b': ";
cin>>b;
cout<<"Enter How Many Iteration Do You Want?: ";
cin>>itr;
cout<<"The function used is x=cubic root (48)\n"<<endl;
cout<<"a = "<<a<<endl;
cout<<"b = "<<b<<endl;
regulaFalsi(a, b, itr);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment