ldo regula
Regula Falsi方法 (Regula Falsi method)
About the method:
关于方法:
We often hear many children and even many adults complaining about the difficulty level that they face while solving complex polynomial equations. It is also difficult for many to follow the steps in a scientific calculator and find the roots of the equations.
我们经常听到许多儿童甚至许多成人抱怨他们在解决复杂的多项式方程式时面临的困难程度。 对于许多人来说,遵循科学计算器中的步骤并找到方程式的根源也是困难的。
Therefore, this is a program that would help engineering students and many shopkeepers, vendors to solve complex equations via the False Position method or the Regula Falsi method. It is also handy, easy and calculations need not be done.
因此,该程序可以帮助工程专业的学生以及许多店主,供应商通过False Position方法或Regula Falsi方法求解复杂的方程式。 它也方便,容易并且不需要进行计算。
Though this is an old method and not much used now it can be useful for those students who are willing to work on a complex project and on a difficult topic like this as they can create a better impression on their professors and fetch more marks. The method used is:
尽管这是一种古老的方法,但现在很少使用,但对于愿意从事复杂项目和类似难题的学生来说,它可能会很有用,因为他们可以给教授留下更好的印象并获得更多的分数。 使用的方法是 :
We start this procedure by locating two points x0 and x1 where the function has opposite signs. We now connect the two points f(x0) and f(x1) by a straight line and find where it cuts the x-axis. Let it cut the axis at x2. We find f(x2). If f(x2) and f(x0) are of opposite signs then we replace x1 by x2 and draw a straight line connecting f(x2) to f(x0) to find the new intersection point. If f(x2) and f(x0) are of the same sign then x0 is replaced by x2 and proceed as before. In both cases, the new interval of search is smaller than the initial interval and ultimately it is guaranteed to converge to the root.
我们通过定位函数具有相反符号的两个点x 0和x 1来开始此过程。 现在,我们通过一条直线连接两个点f(x 0 )和f(x 1 ),并找到它在x轴上的切割位置。 让它在x 2处切割轴。 我们找到f(x 2 )。 如果f(x 2 )和f(x 0 )具有相反的符号,则我们将x 1替换为x 2并绘制一条将f(x 2 )连接到f(x 0 )的直线以找到新的交点。 如果f(x 2 )和f(x 0 )具有相同的符号,则将x 0替换为x 2并像以前一样进行。 在这两种情况下,新的搜索间隔都小于初始间隔,并最终保证了收敛到根。
We will now get an equation to find the successive approximations to the root:
现在,我们将得到一个方程式,以求根的逐次逼近:
Problem:
问题:
To find the roots of the given polynomial equation using the Regula Falsi method. Here, we take the equation in the form of f(x) = ax2+ bx+c if the equation is a quadratic equation.
使用Regula Falsi方法查找给定多项式方程的根。 在这里,如果方程是二次方程,则采用f(x)= a x 2 + b x + c的形式。
Example: f(x) = x2-25
例如:f(x)= x 2 -25
In this method, we need to assume 2 numbers which might be the roots of the equation by equating the equation f(x) to zero {f(x) = 0}. If the actual roots do not lie between or are near to the assumed values, the program will not run. And if the actual roots lie between the assumed values then the program will give the approximate of exact answer.
在此方法中,我们需要通过将方程f(x)等于零{f(x)= 0}来假设2个数字可能是方程的根。 如果实际根不在假设值之间或附近,则程序将不会运行。 如果实际根位于假设值之间,则程序将给出精确答案的近似值。
Example/program:
示例/程序:
#include <stdio.h>
#include <math.h>
#define ep 0.001
float poly(float ar[], int, float);
int main()
{
float a[10],y0,y1,y2,x0,x1,x2,s,r;
int i,n;
char flag;
printf("\t\t\t*****REGULA FALSI METHOD*****");
//enter 2 if it is quadratic eq.
printf ("\n\n Please enter the degree of polynomial equation: ");
scanf ("%d", &n);
if (n>1)
{
for (i=0;i<=n; i++)
{
printf ("Enter the coefficient of x to the power %d: ", i);
scanf ("%f", &a[i]);
}
do
{
//enter assumed values of roots
printf ("\n Enter the initial guesses of x0 and x1: ");
scanf ("%f %f",&x0,&x1);
y0=poly (a, n, x0);
y1=poly (a, n, x1);
} while (y0*y1>0);
printf ("\n x0 x1 x2 y0 y1 y2");
for (i=0; i<=100; i++)
{
s= (x0*y1)-(y0*x1);
r= y1-y0;
x2 = s/r;
y2 = poly (a, n, x2);
if (fabs (y2)<= ep)
{
flag ='T';
break;
}
printf("\n %f %f %f %f %f %f",x0,x1,x2,y0,y1,y2);
if ((y2*y0)<0)
{
x1=x2;
y1=y2;
}
else
{
x0=x2;
y0=y2;
}
}
if(flag=='T')
printf("\n\n Convergent solution= %f",x2);
else
printf("Does not converge in 100 iterations.");
}
else
{
printf("\n\tDegree not acceptable!");
}
return 0;
}
float poly(float ar[],int n,float x)
{
int i;
float p;
p=ar[n];
for(i=n;i>=1;i--)
{
p=ar[i-1]+(x*p);
}
return (p);
}
Output:
输出:
翻译自: https://www.includehelp.com/algorithms/find-the-roots-of-a-complex-polynomial-equation-using-regula-falsi-method-in-c.aspx
ldo regula