chord2.c

来自「解非线性方程的双点弦截法的c程序」· C语言 代码 · 共 34 行

C
34
字号
/* chord2.c: two points chord iterative method */
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#ifndef EPSILON
#define EPSILON 1.0e-8
#endif
double f(double x);
int chord2(double x[2])
{
  int k;
  double xx,y0,y1;
  k=1;
  y0=f(x[0]);
  printf("  0  %12.8f\n",x[0]);
  again:printf("%3d %12.8f\n",k,x[1]);
        k=k+1;
		y1=f(x[1]);
		if(fabs(y1)<EPSILON) {xx=x[1];k=k-1;goto endd;}
		if(fabs(y1-y0)>EPSILON*EPSILON)
		          xx=x[1]-y1*(x[1]-x[0])/(y1-y0);
	     else
		 {
		   printf("f'(x) to small absolutely!Strike any key to exit,\n");
		   getch(); exit(1);
		 }
		 y0=y1;
		 x[0]=x[1];
		 if(fabs(x[1]-xx)<EPSILON) goto endd;
		 x[1]=xx;
		 if(k<MI) goto again;
  endd:  x[1]=xx;
  return(k);
}

⌨️ 快捷键说明

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