/* 牛顿迭代法 编程c语言
求下面方程的根x*x*x-E*x*x+A=0*/
#include <stdio.h>
#include <math.h>
#define MN 51
int RN=1;
double X0[MN],Y0[MN],Z0[MN],X1[MN],ERR[MN];
double A0=1.0,B0=3.0,EPS=0.4E-13;
int SHURUSHUJU()
{
float B,R,GN,GM,TN,TM,CM,I;
double A,D,E;
printf("CN:导线应力δn CM:导线应力δm\n");
printf("TN:温度tn? TM:温度tm\n");
printf("GN:导线比载gn GM:导线比载gm\n");
printf("I:线路档距L F:导线弧垂 f\n");
printf("B:弹性伸长系数β R:温度膨胀系数α\n");
printf("请按以下参数输入:\n");getch();
scanf("%f,%f,%f,%f",&B,&R,&GN,&GM);
scanf("%f,%f,%f,%f",&TN,&TM,&CM,&I);
A=I*I*GN*GN/24/B;
D=I*I*GM*GM/24/B/CM/CM;
E=CM-D-R/B*(TN-TM)
double f(double x){return x*x*x-E*x*x-A;}
double g(double x){return 3*x*x-2*E*x;}
}
int NEWTON()
{
int k;
if (f(A0)>0 ) X0[0]=A0;
else X0[0]=B0;
Y0[0]=f(X0[0]);
Z0[0]=g(X0[0]);
X1[0]=X0[0]-Y0[0]/Z0[0];
ERR[0]=fabs(X1[0]-X0[0]);
for(k=1;k<MN;k++)
{
X0[k]=X1[k-1];
Y0[k]=f(X0[k]);
Z0[k]=g(X0[k]);
X1[k]=X0[k]-Y0[k]/Z0[k];
ERR[k]=fabs(X1[k]-X0[k]);
if(ERR[k]<EPS)break;
}
RN=k+1;
return 0;
}
int ShowTable()
{
int K;
printf("===================================================\n");
printf(" K X0[K] Y0[K] Z0[K] ERR[K] \n");
printf("---------------------------------------------------\n");
for(K=0;K<RN;K++)
printf("\n %2d %10.6f %12.8f %12.8f %12.4e",K,X0[K],Y0[K],Z0[K],ERR[K]);
printf("\n--------------------------------------------------\n");
printf(" 解为=%12.8f",X0[RN-1]);
printf("\n==================================================\n");
return 0;
}
void main()
{
SHURUSHUJU()
NEWTON();
ShowTable();
}
我的邮箱ffg8435@163.com