📄 『 高性能计算 』 - 高斯消去解方程组c++程序(复杂度 n^3).htm
字号:
<TABLE align=center border=0 cellPadding=0 cellSpacing=0 width="97%">
<TBODY>
<TR>
<TD bgColor=#000000 height=24 width=1></TD>
<TD bgColor=#f2f8ff>
<TABLE bgColor=#f2f8ff cellPadding=4 cellSpacing=0 width="100%">
<TBODY>
<TR>
<TD bgColor=#f2f8ff rowSpan=2 vAlign=top width=178><IMG height=4
src="" width=0><BR>
<TABLE border=0 cellPadding=0 cellSpacing=0>
<TBODY>
<TR>
<TD width=30> <IMG alt=该用户目前不在线 height=15
src="『 高性能计算 』 - 高斯消去解方程组c++程序(复杂度 n^3).files/offline1.gif"
width=15></TD>
<TD>
<TABLE
style="FILTER: glow(color=#996699,direction=135)"> <FONT
color=#ffffff><B>海阔天空</B></FONT>
<TBODY></TBODY></TABLE></TD>
<TD> <IMG alt=哦,帅哥哟 height=14
src="『 高性能计算 』 - 高斯消去解方程组c++程序(复杂度 n^3).files/mal.gif"
width=20> <IMG alt=此人为版主
src="『 高性能计算 』 - 高斯消去解方程组c++程序(复杂度 n^3).files/teammo.gif"
width=16></TD></TR></TBODY></TABLE> <FONT color=#555555>头衔:
论坛版主<BR></FONT> <FONT color=#333333></FONT> <BR> <IMG
height=90 src="『 高性能计算 』 - 高斯消去解方程组c++程序(复杂度 n^3).files/4_1472.gif"
width=74> <BR> <IMG height=16
src="『 高性能计算 』 - 高斯消去解方程组c++程序(复杂度 n^3).files/pips4.gif" width=100>
<BR> <FONT color=#555555>威望: 0</FONT> <BR> <FONT
color=#333333>级别: <A
href="http://www.lasg.ac.cn/cgi-bin/forum/lookinfo.cgi?action=style"
target=_blank>精灵王</A></FONT> <BR> <FONT color=#555555>来自: 安徽合肥
</FONT><BR> <FONT color=#333333>鉴定: 已设置保密</FONT>
<BR> <FONT color=#555555>魅力: <IMG alt=3921 height=8
src="『 高性能计算 』 - 高斯消去解方程组c++程序(复杂度 n^3).files/bar4.gif"
width=20></FONT> <BR> <FONT color=#333333>经验: <IMG alt=100
height=8 src="『 高性能计算 』 - 高斯消去解方程组c++程序(复杂度 n^3).files/bar5.gif"
width=1></FONT> <BR> <FONT color=#555555>金钱: 5413 雷傲元</FONT>
<BR> <FONT color=#333333>总发贴数: <B>378</B> 篇</FONT>
<BR> <FONT color=#555555>注册日期: 2004/02/02</FONT><BR><IMG
height=4 src="" width=0><BR></TD>
<TD bgColor=#f2f8ff height="100%" rowSpan=2 width=1>
<TABLE bgColor=#90c8ff cellPadding=0 cellSpacing=0 height="100%"
width=1>
<TBODY>
<TR>
<TD width=1></TD></TR></TBODY></TABLE></TD>
<TD bgColor=#f2f8ff height="100%" vAlign=top width=*><IMG height=4
src="" width=0><BR> <A
href="javascript:openScript('messanger.cgi?action=new&touser=海阔天空',420,320)"
title=给海阔天空发送一个短消息><IMG border=0 height=16
src="『 高性能计算 』 - 高斯消去解方程组c++程序(复杂度 n^3).files/message.gif"
width=16>消息</A> <A
href="http://www.lasg.ac.cn/cgi-bin/forum/profile.cgi?action=show&member=海阔天空"
title=查看海阔天空的个人资料><IMG border=0 height=16
src="『 高性能计算 』 - 高斯消去解方程组c++程序(复杂度 n^3).files/profile.gif"
width=16>查看</A> <A
href="http://www.lasg.ac.cn/cgi-bin/forum/search.cgi?action=startsearch&TYPE_OF_SEARCH=username_search&NAME_SEARCH=topictitle_search&FORUMS_TO_SEARCH=4&SEARCH_STRING=海阔天空"
target=_blank title=搜索海阔天空在本分论坛的全部贴子><IMG border=0 height=16
src="『 高性能计算 』 - 高斯消去解方程组c++程序(复杂度 n^3).files/find.gif"
width=16>搜索</A> <A
href="javascript:openScript('friendlist.cgi?action=adduser&adduser=海阔天空',420,320)"
title=加海阔天空为我的好友><IMG border=0 height=16
src="『 高性能计算 』 - 高斯消去解方程组c++程序(复杂度 n^3).files/friend.gif"
width=16>好友</A> <A href="mailto:ahzhming@163.com" title=电子邮件地址><IMG
border=0 height=16
src="『 高性能计算 』 - 高斯消去解方程组c++程序(复杂度 n^3).files/email.gif"
width=16>邮件</A> <A
href="http://www.lasg.ac.cn/cgi-bin/forum/post.cgi?action=copy1&forum=4&topic=1462&postno=1"
title=复制这个贴子><IMG border=0 height=16
src="『 高性能计算 』 - 高斯消去解方程组c++程序(复杂度 n^3).files/copy.gif"
width=16>复制</A> <A
href="http://www.lasg.ac.cn/cgi-bin/forum/post.cgi?action=replyquote&forum=4&topic=1462&postno=1"
title=引用回复这个贴子><IMG border=0 height=16
src="『 高性能计算 』 - 高斯消去解方程组c++程序(复杂度 n^3).files/reply.gif"
width=16>引用</A> <A
href="http://www.lasg.ac.cn/cgi-bin/forum/post.cgi?action=reply&forum=4&topic=1462"><IMG
alt=回复贴子 border=0 height=16
src="『 高性能计算 』 - 高斯消去解方程组c++程序(复杂度 n^3).files/replynow.gif"
width=16>回复</A> <BR>
<HR color=#000000 SIZE=1 width="100%">
<TABLE cellPadding=0 cellSpacing=0 style="TABLE-LAYOUT: fixed"
width="100%">
<TBODY>
<TR>
<TD vAlign=top width=32><IMG height=13
src="『 高性能计算 』 - 高斯消去解方程组c++程序(复杂度 n^3).files/00.gif"
width=13> </TD>
<TD
style="LEFT: 0px; LETTER-SPACING: 0pt; LINE-HEIGHT: 130%; WIDTH: 100%; WORD-WRAP: break-word"><FONT
color=#555555><FONT color=#555555><BR><BR>#include
<iostream> <BR>#include <fstream> <BR>#include
<iomanip> <BR>#include <cmath> <BR>#include
<algorithm> <BR><BR>using namespace std;
<BR><BR>ifstream fin("guass.in"); <BR><BR>#define NN 100
<BR>
//
g是系数巨阵n*n,b是增广向量n, <BR>double
g[NN][NN],b[NN],x[NN]; // x是方程组的解n维。
<BR>int n;
//
下标一律以零开始计算。 <BR>
// <BR>bool guass();
//
guass()函数对以上参数进行求解方程组 <BR>
// 并将结果放入x中。 <BR><BR>void
outg(); <BR>void in(); <BR><BR>int main() <BR>{ <BR>
fin>>n; <BR> in(); <BR> if (!guass())
cout<<"No solution!"<<endl; <BR>
else{ <BR> for (int
i=0;i<n;i++) <BR>
cout<<"x [ "<<i<<" ]=
"<<x<<endl; <BR>
cout<<endl; <BR> }
<BR><BR><BR> getchar(); <BR> fin.close();
<BR> return 0; <BR>} <BR>void in() <BR>{ <BR> int
i,j; <BR> for (i=0;i<n;i++) { <BR>
for (j=0;j<n;j++) <BR>
fin>>g[j]; <BR> fin>>b;
<BR> } <BR> return; <BR><BR>}
<BR><BR>bool guass() <BR>{ <BR> int i,j,k,p; <BR>
int flag[NN]; <BR> double l; <BR>
memset(flag,0,sizeof(flag)); <BR><BR> for
(i=0;i<n;i++){ <BR> p=-1; <BR>
for (j=0;j<n;j++) <BR>
if (!flag[j]) <BR> if
(fabs(g[j]-0.0)>1e-8) <BR>
if (p==-1) p=j; <BR>
else <BR>
if
(fabs(g[p])+1e-8<=fabs(g[j])) p=j; <BR>
cout<<"p="<<p<<endl; <BR>
flag[p]=1; <BR> if (p==-1) return
false; <BR> for (j=0;j<n;j++) <BR>
if (p!=j){ <BR>
l=g[j]/g[p]; <BR>
for (k=i;k<n;k++) <BR>
g[j][k]-=g[p][k]*l;
<BR> b[j]-=b[p]*l;
<BR> } <BR>
outg(); <BR> } <BR><BR>
for (i=0;i<n;i++) <BR> for
(j=0;j<n;j++) <BR> if
(fabs(g[j]-0.0)>1e-8){ <BR>
x[j]=b/g[j]; <BR>
break; <BR> }
<BR> return true; <BR><BR>} <BR><BR>void outg() <BR>{
<BR> int i,j; <BR> cout.setf(ios::fixed);
<BR> cout.precision(2); <BR> for
(i=0;i<n;i++){ <BR> for (j=0;j<n;j++)
<BR>
cout<<setw(8)<<g[j]; <BR>
cout<<setw(8)<<b; <BR>
cout<<endl; <BR> } <BR>
return; <BR><BR>} <BR><BR>--
<TABLE border=0 cellPadding=0 cellSpacing=0 width="100%">
<TBODY>
<TR>
<TD><BR><BR>------------------------------------------------------------------------------------<BR>与人方便,与己方便。<BR>学得越多,问题越多;为别人解决的问题越多,自己学的东西也越多。<BR>寻找Genetic
Programming爱好者。</TD></TR></TBODY></TABLE><BR></FONT></FONT></TD>
<TD width=16></TD></TR></TBODY></TABLE></TD></TR>
<TR>
<TD bgColor=#f2f8ff class=bottomline vAlign=bottom>
<HR color=#000000 SIZE=1 width="100%">
<TABLE cellPadding=0 cellSpacing=0 width="100%">
<TBODY>
<TR>
<TD vAlign=bottom><FONT color=#555555> <A
href="http://www.lasg.ac.cn/cgi-bin/forum/postings.cgi?action=edit&forum=4&topic=1462&postno=1"
title=编辑这个贴子><IMG border=0 height=15
src="『 高性能计算 』 - 高斯消去解方程组c++程序(复杂度 n^3).files/edit.gif"
width=16>编辑</A> <A
href="http://www.lasg.ac.cn/cgi-bin/forum/postings.cgi?action=directdel&forum=4&topic=1462&postno=1"
title=删除这个回复><IMG align=absMiddle border=0 height=16
src="『 高性能计算 』 - 高斯消去解方程组c++程序(复杂度 n^3).files/a_delete.gif"
width=52></A> <IMG alt=发贴时间 height=15
src="『 高性能计算 』 - 高斯消去解方程组c++程序(复杂度 n^3).files/posttime.gif"
width=16>2004/04/27 10:36am <IMG alt="" height=15
src="『 高性能计算 』 - 高斯消去解方程组c++程序(复杂度 n^3).files/ip.gif"
width=13>IP: 已设置保密</FONT></TD>
<TD align=right vAlign=bottom width=110 nowarp></TD></FORM>
<TD align=right vAlign=bottom width=4></TD></TR></TBODY></TABLE><IMG
height=4 src="" width=0><BR></TD></TR></TBODY></TABLE></TD>
<TD bgColor=#000000 height=24 width=1></TD></TR></TBODY></TABLE>
<TABLE align=center bgColor=#000000 border=0 cellPadding=0 cellSpacing=0
width="97%">
<TBODY>
<TR>
<TD height=1></TD></TR></TBODY></TABLE>
<TABLE align=center border=0 cellPadding=0 cellSpacing=0 width="97%">
<TBODY>
<TR>
<TD bgColor=#000000 height=24 width=1></TD>
<TD bgColor=#e8f4ff>
<TABLE bgColor=#e8f4ff cellPadding=4 cellSpacing=0 width="100%">
<TBODY>
<TR>
<TD bgColor=#e8f4ff rowSpan=2 vAlign=top width=178><IMG height=4
src="" width=0><BR>
<TABLE border=0 cellPadding=0 cellSpacing=0>
<TBODY>
<TR>
<TD width=30> <IMG alt=该用户目前不在线 height=15
src="『 高性能计算 』 - 高斯消去解方程组c++程序(复杂度 n^3).files/offline1.gif"
width=15></TD>
<TD>
<TABLE
style="FILTER: glow(color=#996699,direction=135)"> <FONT
color=#ffffff><B>ustcsunl</B></FONT>
<TBODY></TBODY></TABLE></TD>
<TD> <IMG alt=哦,帅哥哟 height=14
src="『 高性能计算 』 - 高斯消去解方程组c++程序(复杂度 n^3).files/mal.gif"
width=20> <IMG alt=此人为版主
src="『 高性能计算 』 - 高斯消去解方程组c++程序(复杂度 n^3).files/teammo.gif"
width=16></TD></TR></TBODY></TABLE> <FONT color=#555555>头衔:
论坛版主<BR></FONT> <FONT color=#333333></FONT> <BR> <IMG
src="『 高性能计算 』 - 高斯消去解方程组c++程序(复杂度 n^3).files/69-1.gif">
<BR> <IMG height=16
src="『 高性能计算 』 - 高斯消去解方程组c++程序(复杂度 n^3).files/pips5.gif" width=100>
<BR> <FONT color=#555555>威望: +1</FONT> <BR> <FONT
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -