📄 falsepos.c
字号:
/* TO SOLVE AN EQUATION BY METHOD OF FALSE POSITION */
#include<stdio.h>
#include<math.h>
float f(float x)
{
return (x * x - 25);
}
void fposition(float,float,float,float);
void main()
{
float x0,x1,e,n;
clrscr();
printf("\n\t ***** FALSE POSITION METHOD *****");
printf("\n Enter the value of x0,x1,error and n...\n");
scanf("%f %f %f %f",&x0,&x1,&e,&n);
fposition(x0,x1,e,n);
getch();
}
void fposition( float x0,float x1,float e,float n)
{
float y0,y1,x2,y2;
int i;
y0 = f(x0);
y1 = f(x1);
printf("\ni\tx0\tx1\tx2\ty0\t\ty1\t\ty2\n\n");
for (i=0;i<n;i++)
{
x2 =(((x0*y1)-(x1*y0))/(y1-y0));
y2 =f(x2);
printf("%d\t%.3f\t%.3f\t%.3f\t%.3f\t\t%.3f\t\t%.3f\n",i,x0,x1,x2,y0,y1,y2);
if(fabs(y2) <= e)
{
printf("\n Convergent solution!");
printf("\n X0 = %.3f,\n X1 = %.3f \n X2 = %.3f",x0,x1,x2);
printf("\n Y0 = %.3f,\n Y1 = %.3f \nY2 = %.3f",y0,y1,y2);
getch();
exit();
}
if((y2*y1)>0)
{
x1 = x2;
y1 = y2;
}
else
{
x0 = x2;
y0 = y2;
}
}
printf("\n\t Solution does not converges in n iterations !!!");
printf("\n X2 = %.3f,\n Y2 = %.3f",x2,y2);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -