C++ Program for Regula Falsi Method
C++ program for regula falsi method. This page provides program for regula falsi method in c++ language. To understand regula falsi method with definition, formula, example, graph, theory, advantages and disadvantages, application read Regula Falsi Method.
C++ program for regula falsi method
Here is c++ program for regula falsi or false position method.
#include<bits/stdc++.h>
using namespace std;
#define MAX_ITER 1000000
double func(double x)
{
return x*x*x - x*x + 2;
}
void regula_falsi(double number1, double number2)
{
if (func(number1) * func(number2) >= 0)
{
cout << "You have not assumed right number1 and number2\n";
return;
}
double root = number1;
for (int i=0; i < MAX_ITER; i++)
{
c = (number1*func(number2) - number2*func(numnber1))/ (func(number2) - func(number1));
if (func(c)==0)
break;
else if (func(c)*func(a) < 0)
number2 = root;
else
number1 = root;
}
cout << "The value of root is : " << root;
}
int main()
{
double number1 =-200, number2 = 300;
regula_falsi(a, b);
return 0;
}
Output:
The value of root is : -1
Comments
Post a Comment