#include<stdio.h>#include<stdlib.h>typedef struct Complex{float real;float image;}Complex;Complex InitComplex(float a,float b){ Complex c; c.real=a; c.image=b; return c;}Complex Add(Complex c1,Complex c2){ Complex sum; sum.real=c1.real+c2.real ; sum.image=c1.image+c2.image ; return sum;}...
例1 用牛顿迭代法求方程f(x)=x - e-x=0在区间(0,1)内的根,输出每次的迭代结果并统计所用的迭代次数,取ε=10-5,x0=0.5。程序清单:#include<stdio.h>#include<conio.h>#include<math.h>#define MAXREPT 1000 /* 最大迭代次数 */
float f(float x){ return(x-exp(-x)); /* 函数f(x) */}float df(float x) /* 导函数f’(x) */{ return(1+exp(-x));}float iterate (f...
加速法
#include<stdio.h>#include<math.h>void main(){ float work_out(float x); float f1(float x); float a; printf("input origial:\n"); scanf("%f",&a); f1(a); printf("%0.3f",work_out(a));}float f1(float x){ x=(sin(x))/(x); return(x);}
float work_out(float x){ float x1,x2,x3; do{ x1=f1(x); x2...