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

📄 bisect.c

📁 Bisection Method - Numerical ananlysis
💻 C
字号:
#include<stdio.h>#include<math.h>bisection(){	int i, count = 0;	float a,b,x,fa,fb,fx,tol;	printf(" \n Given equation is 2*x^2-1");	printf("\n Enter the value of a and b : ");	scanf("%f %f", &a,&b);	tol=0.005;	printf("\n Resultant table is :");	printf("\n\n a \t\tb \tx \tfa \tfb \tfx");	//while((fabs(x-a)> tol) || (fabs(x-b)> tol))		do{		fa=(2*(a*a))-1;		fb=(2*(b*b))-1;		x=(a+b)/2;		fx=(2*(x*x))-1;		printf("\n%f %f %f %f %f %f", a,b,x,fa,fb,fx);			if(fx>0)			b=x;		else			a=x;		 count++;			printf("\n");	}while((fabs(x-a)> tol) || (fabs(x-b)> tol));	printf("\n The root of given equation is %f\n", x);	printf("\n The number of iterations are %d",count);}newton(){	float x,fx,x1,fx1, tol,temp;	int i,count;		x=1.5;	int maxiter=0;	printf("The equation to be solved is x^3+4*x^2-10 ");	printf("\n The derivative is 3*x^2+8*x");	tol =0.0005 ;	printf("\n Resultant table is :");	printf("\n\n x \t  fx \t  fx1\t x1");	count=0;	do	{		temp=x;		fx=(x*x*x)+(4*x*x)-10;						fx1=3*(x*x) + (8*x);		x1 = x - (fx/fx1);		printf("\n%f\t%f\t%f\t%f", x,fx,fx1,x1);		x = x1;		count++;					}while(fabs(x1 -temp)> tol);	printf("\n\n approximate root is %f\n",x1);	printf("\n The number of iterations are %d",count);}fixed(){	int i, count;	float x, fx, x1, tol,temp;	printf(" \n Given equation is((10 - x ^ 3)^1/2)/2 ");	printf("\n Enter the value of x0 : ");	scanf("%f", &x);	tol= 0.005;	printf("\n Resultant table is :");	printf("\n\n   x \t\t  fx");	count=0;	do	{		temp=x;		fx=(sqrt(10 - (x*x*x)))/2;		x = fx;		printf("\n%f\t%f", x, fx);		count++;		printf("\n");	}while(fabs(fx - temp) > tol);	printf("\n The root of given equation is %f\n", x);	printf("\n The number of iterations are %d",count);}int main(){     int ch;      do{               printf("\n1) Bisection");     printf("\n2) Newton Raphson");     printf("\n3) Fixed point");         printf(" \n Enter your choice (1/2/3): ");     scanf("%d",&ch);          switch(ch)     {        case 1: bisection();                break;                        case 2: newton();                break;                        case 3: fixed();                break;                                                default: printf("Wrong choice....");                   }      }while(ch!=3);}

⌨️ 快捷键说明

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