📄 aitken加速收敛法.cpp
字号:
//*************************************
//程序功能:Aitken加速收敛法 求线性方程的解
//
//作 者:杭永东
//
//日 期: 2002.03.26
//*************************************
#include <math.h>
#include <iostream.h>
#include <stdio.h>
//*************************************
//
//注:更改此宏定义的表达式可以解不同的线性方程
// 根据宏定义要求,x必须以(x)形式出现式中
//
//*************************************
#define fi(x) tan((x))
long double x0,e;
long double Dd(long double x0)
{
long double x1=fi(x0);
long double x2=fi(x1);
long double x3=fi(x2);
long double y0=x0-pow((x1-x2),2.0L)/(x2-2.0L*x1+x0);
long double y1=x1-pow((x2-x1),2.0L)/(x3-2.0L*x2+x1);
if((((y1-y0)>0)? (y1-y0): (y0-y1))<e)
return y1;
return Dd(y1);
}
main()
{
cout<<"Please input x0,e:";
cin>>x0>>e;
printf("\n%.9f",Dd(x0));
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -