⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bisectio.c

📁 queues implementation
💻 C
字号:
/* TO SOLVE AN EQUATION BY BISECTION METHOD */

#include<stdio.h>
#include<math.h>

float f(float x)
{
	return (x * x -  25);
}

void bisection(float,float,float);

void main()
{
	float x0,x1,e;
	clrscr();
	printf("\n\t ***** BISECTION METHOD *****");
	printf("\n Enter the value of x0,x1,delta(error)...\n");
	scanf("%f %f %f",&x0,&x1,&e);
	bisection(x0,x1,e);
	getch();
}

void bisection( float x0,float x1,float e)
{
	float y0,y1,x2,y2;
	int i;
	y0 = f(x0);
	y1 = f(x1);
	i = 0;

	if(( y0 * y1) > 0)
	{
		printf("\n Starting Values Unsuitable!!!");
		printf("\n X0=%f \n X1=%f \n Y0=.4%f \n Y1=.4%f",x0,x1,y0,y1);
		getch();
		exit();
	}
       printf("i\tx0\tx1\tx2\ty0\t\ty1\t\ty2\n\n");
       while ((fabs(x1-x0)/x1) > e)
       {
		x2=(x0+x1)/2;
		y2 = f(x2);
		printf("%d\t%.3f\t%.3f\t%.3f\t%.3f\t\t%.3f\t\t%.3f\n",i,x0,x1,x2,f(x0),f(x1),y2);
		i++;
		if((y2)<0)
			x0 = x2;
		else
			x1 = x2;
	}
	printf("\n Solution converges to a root!!\n");
	printf("\n No of iterations:%d",i);
	printf("\n X2 =%f, \n Y2 = %f",x2,y2);
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -