文档下载 文档下载导航
设为首页 | 加入收藏
搜索 请输入内容:  
 导航当前位置: 文档下载 > 所有分类 > 高等教育 > 工学 > iteration
侵权投诉

iteration

本程序可以用雅可比迭代法,塞德尔迭代法,逐次超松弛法求解线性方程组 已经在visual studio2005中调试通过!

r(i=1;i<n+1;i++)
cout<<"X["<<i<<"]"<<" ";
cout<<"精度";
cout<<endl;
cout<<"迭代初值为: ";
cout<<setiosflags(ios::fixed);
for(i=0;i<n;i++)
cout<<y[i]<<" ";
cout<<endl;
while(e>fff)
{
for(i=0;i<n;i++)
z[i]=y[i];
for(i=0;i<n;i++)
{
nn=0;
for(j=0;j<n;j++)
{
if(i!=j)
nn=nn+x[i][j]*z[j];
y[i]=nn+b[i];
}
e=fabs(z[0]-y[0]);
if(fabs(z[i]-y[i])>e)
e=fabs(z[i]-y[i]);
if(i==0)
{
cout<<setiosflags(ios::fixed);
cout<<"第"<<setw(3)<<setprecision(3)<<f++<<"次迭代"<<" ";
}
cout<<setiosflags(ios::fixed);
cout<<setw(8)<<setprecision(8)<<y[i]<<" ";
}
cout<<e;
cout<<endl;
if(f>mm)
{
cout<<"迭代次数大于"<<mm<<"次"<<endl;
cout<<"认为方程发散,迭代不收敛"<<endl;
exit(1);
}
}
cout<<endl;
cout<<endl;
cout<<"方程迭代了"<<f-1<<"次,达到你所要求的精度"<<fff<<endl;
cout<<"最后结果为:"<<endl;
cout<<endl;
for(i=0;i<n;i++)
{
cout<<"X"<<"["<<i+1<<"]"<<"="<<y[i];
cout<<endl;
}
exit(1);
//***********************************塞德尔迭代法********************************
aa:cout<<" ";
for(i=1;i<n+1;i++)
cout<<"X["<<i<<"]"<<" ";
cout<<"精度";
cout<<endl;
cout<<"迭代初值为: ";
cout<<setiosflags(ios::fixed);
for(i=0;i<n;i++)
cout<<y[i]<<" ";
cout<<endl;
while(e>fff)
{
for(i=0;i<n;i++)
{
z[i]=y[i];
nn=0;
for(j=0;j<n;j++)
{
nn=nn+x[i][j]*y[j];
y[i]=nn+b[i];
}
e=fabs(z[0]-y[0]);
if(fabs(z[i]-y[i])>e)
e=fabs(z[i]-y[i]);
if(i==0)
{
cout<<setiosflags(ios::fixed);
cout<<"第"<<setw(3)<<setprecision(3)<<f++<<"次迭代"<<" ";
}
cout<<setiosflags(ios::fixed);
cout<<setw(8)<<setprecision(8)<<y[i]<<" ";
}
cout<<e;
cout<<endl;
if(f>mm)
{
cout<<"迭代次数大于"<<mm<<"次"<<endl;
cout<<"认为方程发散,迭代不收敛"<<endl;
exit(1);
}
}
cout<<endl;
cout<<endl;
cout<<"方程迭代了"<<f-1<<"次,达到你所要求的精度"<<fff<<endl;
cout<<"最后结果为:"<<endl;
cout<<endl;
for(i=0;i<n;i++)
{
cout<<"X"<<"["<<i+1<<"]"<<"="<<y[i];
cout<<endl;
}
exit(1);
//***********************************逐次超松弛法********************************
dd: cout<<"输入加速因子W(0<W<2):"<<endl;
cin>>w;
/*if((w>2)||(w<0))
{
cout<<"输入错误!加速因子W(0<W<2):"<<endl;
cout<<"请重新输入:"<<endl;
cin>>w;
}*/
//不知道为什么写成这样大于2能判断,而小于0就不能判断老?????

if(w>=2)//还有w>=2,w<=0输入0或2时也不能判断!!
{
cout<<"输入错误!加速因子W(0<W<2):"<<endl;
cout<<"请重新输入:"<<endl;
cin>>w;
}
if(w<=0)
{
cout<<"输入错误!加速因子W(0<W<2):"<<endl;
cout<<"请重新输入:"<<endl;
cin>>w;
}
cout<<" ";
for(i=1;i<n+1;i++)
cout<<"X["<<i<<"]"<<" ";
cout<<"精度";
cout<<endl;
cout<<"迭代初值为: ";
cout<<setiosflags(ios::fixed);
for(i=0;i<n;i++)
cout<<y[i]<<" ";
co

上一页第2页

你可能喜欢

热门文档

相关文档

  • 2.2 fixed-point iteration.doc

    2.2 Fixed-Point Iteration (1) Introduction A fixed point for a given function g is a number p for which g(p)=p. Root-finding problem: f(p)=...

  • RUP Iteration

    SEI 软件工程研究所 Xidian University Software School RUP -- Iteration Iteration vs. Disciplines SEI 软件工程研究所 Xidian University Software School RUP -- ...

  • BY FUNCTIONAL ITERATION

    The main advantage of division by functional iteration is...更多>>A class of high performance division algorithms is functional iteration. Division by ...

  • 4.2 Fixed-Point Iteration

    4.2 Fixed-Point Iteration_理学_高等教育_教育专区。合工大数值分析中英文课件4.2 Fixed-Point Iteration 4.2.1 Basic Concepts 4.2.2 Convergence Analysis ...

  • Tangent Graeffe Iteration

    Graeffe iteration was the choice algorithm for solving univariate polynomials in the XIX-th and early XX-th century. In this paper, a new variation of...

  • Power Iteration Clustering

    Power Iteration Clustering_IT/计算机_专业资料。Power Iteration Clustering Speaker: Xiaofei Di 2010.10.11 Outline ? ? ? ? ? Authors Abstract Backg...

  • KRYLOV SUBSPACE ITERATION

    KRYLOV SUBSPACE ITERATION Presented by: Nab Raj Roshyara Master and Ph.D. Student Supervisors: Prof. Dr. Peter Benner, Department of Mathematics, TU ...

  • Krylov Subspace Iteration

    Suppose that we approximate the n by n matrix A, of the linear system Ax = b, by the simpler matrix K, then the above sketched iteration process ...

  • LoadRunner中参数的设置

    tester10 迭代次数:2 次 场景设臵(一):Sequential+Each Iteration 执行结果: VuGen 中:1 个用户 第一次迭代(Iteration)取值为 tester1 第二次迭代(Iteration)...

  • Comonadic Iteration #

    The most fundamental and easy to code by a combinator are (simple) iteration and primitive-recursion. Some other schemes that are more general in terms ...

站点地图 | 文档上传 | 侵权投诉 | 手机版
本站所有资源均来自互联网,本站只负责收集和整理,均不承担任何法律责任,如有侵权等其它行为请联系我们.
文档下载 Copyright 2013 doc.guandang.net All Rights Reserved.  -  email