资源简介
该源程序很好的说明了Aitken加速法的整个过程的奥妙
![](http://www.nz998.com/pic/44378.jpg)
代码片段和文件信息
//Aitken解方程
#include
#include
using namespace std;
//定义求迭代函数的值的函数
double iterator_function( double argument)
{
return argument*argument*argument - 1;//返回迭代函数的值
}
//定义解方程的函数
void solve_equal()
{
double firstroot = 1.5;//相当于x(k)
double firstroot_next;
double firstroot_next_next;
int count_iterator = 0;//统计迭代次数
double precision = 0.00001; //预先给定的精度
int max_iterator = 10000;//迭代次数上限
int factor_break = 0;//用于判断跳出循环的因子
do
{
firstroot_next = iterator_function(firstroot);//调用函数
firstroot_next_next = iterator_function(firstroot_next);//调用函数
firstroot = firstroot_next_next - (firstroot_next_next-firstroot_next)*(firstroot_next_next-firstroot_next)/(firstroot_next_next -2*firstroot_next + firstroot);
count_iterator++;//累加
//判断是否达到迭代上限,并给跳出因子赋值
if( count_iterator > max_iterator)
{
cout << “已达到迭代次数上限,在该区间内部存在符合精度的根或迭代函数不收敛“ << endl;
factor_break = 1;break;}
}while(fabs(firstroot-firstroot_next_next)>precision);
if(0 == factor_break)//判断跳出循环因子
{
cout << “方程x*x*x - x-1=0在[12]内的根为:“< cout << “迭代次数为:“<< count_iterator << endl;
}
}
int main()
{
solve_equal();//调用解方程的函数
return 0;
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2010-01-10 20:12 Aitken加速法\
文件 1387 2009-12-07 17:50 Aitken加速法\Aitken.cpp
文件 1199104 2010-01-13 14:52 Aitken加速法\Aitken加速法.ncb
文件 895 2009-12-07 16:56 Aitken加速法\Aitken加速法.sln
文件 8192 2010-01-13 14:52 Aitken加速法\Aitken加速法.suo
文件 3928 2009-12-07 17:01 Aitken加速法\Aitken加速法.vcproj
文件 1409 2010-01-13 14:52 Aitken加速法\Aitken加速法.vcproj.lqx-PC.lqx.user
文件 1427 2009-12-07 18:12 Aitken加速法\Aitken加速法.vcproj.WIN-ER90LEKKVE3.Administrator.user
目录 0 2010-01-10 20:12 Aitken加速法\Debug\
文件 41181 2009-12-07 17:50 Aitken加速法\Debug\Aitken.obj
文件 39936 2009-12-07 17:50 Aitken加速法\Debug\Aitken加速法.exe
文件 663 2009-12-07 17:31 Aitken加速法\Debug\Aitken加速法.exe.em
文件 728 2009-12-07 17:31 Aitken加速法\Debug\Aitken加速法.exe.em
文件 621 2009-12-07 17:50 Aitken加速法\Debug\Aitken加速法.exe.intermediate.manifest
文件 404772 2009-12-07 17:50 Aitken加速法\Debug\Aitken加速法.ilk
文件 584704 2009-12-07 17:50 Aitken加速法\Debug\Aitken加速法.pdb
文件 5704 2009-12-07 17:50 Aitken加速法\Debug\BuildLog.htm
文件 65 2009-12-07 17:50 Aitken加速法\Debug\mt.dep
文件 175104 2009-12-07 17:50 Aitken加速法\Debug\vc90.idb
文件 217088 2009-12-07 17:50 Aitken加速法\Debug\vc90.pdb
- 上一篇:最简单的PI算法(C语言)-用于控制电机转速
- 下一篇:c语言描述超松弛算法的源代码
评论
共有 条评论