本程序为本人参考一些资料后编写,在visual c++6.0下调试通过。
[@more@]///
/简单迭代法:f(x)=0改写成x=g(x)
/原理:x_(k+1)=g(x_k)
/有条件限制,可能不收敛
/改进:输出每一次迭代的结果,将迭代模块做全面
///
#include
#include
#include
using namespace std;
//
double fun(double x);
void SimpleIterative(double(*pf)(double x));
//
//
int main()
{
SimpleIterative(fun);
return 0;
}
//
//
double fun(double x)
{
return pow(x+1,1/3.);///f(x)=x^3-x-1转化成x^3=x+1
}
/
void SimpleIterative(double(*pf)(double x))
{
double x,x0;
int maxflag,k=1;
double err;
cout<>maxflag;
cout<>err;
cout<>x;
cout< do
{
x0=x;
x=pf(x0);
cout< ++k;
}while(fabs(x-x0)>err&&k if(k>=maxflag)
cout< else
{
cout< cout< cout< }
}
/
/
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/11355887/viewspace-974945/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/11355887/viewspace-974945/