资源描述:
《【精品】数值分析与算法.doc》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、数值分析与算法实验报告班级:软件一班学号:20112711姓名:钱巧娅作业2.1Rgauss函数流稈图Main函数流程图STARTEND作业2.1源代码#include#include#includeintrgauss(intn,doublea[l[31,doubleb[]){intl,k,i,j;doubled,t;1=1;for(k=0;k<=n-2;k++){d=0.0;d=a[k][k];for(j=k+1;jv=n・1;j++){a[k][j]=a[k]rj]/d;}b[k]=b[k]/d;for(i=k+l;i<=n-1;i
2、++){for(j=k+l;j<=n-l;j++){a[i]U]=a[i]U]-a[i][k]*a[k]U];)b[i]=b[i]-a[i][k]*b[k];)}d=a[(n-l)][n-l];b[n・l]=b[n-l]/d;for(i=n-2;i>=0;i—){t=0.0;for(j=i+1;j<=n・1;j++)t=t+a[i]lj]*b[j];b[i]=b[i]-t;}return(l);}main(){inti,j;intrgauss(intn,double[][3],doubleb[]);staticdoubleal[][3]={2,-l,3,4,2,5,1,2,0};stati
3、cdoublebl[]={1,4,7};staticdoublea2[][3]={3,-1,2,1,1,1,2,11};staticdoubleb2[]={-3,-4,-3);if(rgauss(3,al,bl)!=0)printf(n(l)n);for(i=0;i<=2;i++)printf("x(%d)=%.4f",(i+l),bl[i]);printf(n(2)M);if(rgauss(3,a2,b2)!=0)for(i=0;i<=2;i++)printfC*x(%d)=%.4fH,(i+1),b2[i]);}结果截图:c*C:Docu>entsandSettin
4、gsVAdainistratorKyDocu>entsC-Freeft1B4<1>x=9.0000x<2>=-1.0000x<3>=-6.0000<2>x=-1.0000x<2>=-2.0000x<3>=-1.0000请按任意键继续•••rgauss函数流程图Main函数流程图(++r.UHv二+常「)」0二(++X.UHV-二+4.11)」OJEgqx兰qCM二3EHS2E一(++「,uhvj+4hd」oj二兰gfp」(0)Emu」(u三£=)七uxd_(SD总)(0丄)七(-FLS二q二s二q丄兰£2一qulH"3s二Esrs二e"二sEsgEE(++r.UHVNHm
5、oJ-亍£)七亍匸兰SS亘2SS二亍立=二忆立=二了(++XIUHV一O丄)」04OMgsnJ二O丄Q〒HOI+P)七一「•ils一TSS「亍P-(PCMX3二E)sqEg(++fuhv¥djoj(++X.UHV三HVOJ00世(++=guhuop)」oj二JI"((1.£)jo(dz-s*u)oo=eujqs-hs「TpCD一qnop5,sr兰4*c一一(二q3qnop」寸三eusnopenlussnesplwcq.q二plsvupnousAq・lppuj:>l)pn一Ou一#£・0一plsxpnpu菇z.z{a[i]rj]=a[i]rj]-a[i][k]*arkl
6、j];}b[i]=b
7、[i]-a[i][k]*b[k];d=a[(n-l)][n-l];if(fabs(d)+1.0==1.0){free(js);printf(,,fail,');return(0);}bln-l]=b[n-l]/d;for(i=n・2;i>=0;i・・){t=0.0;for(j=i+1;j<=n-l;j++)t=t+a[i]U]*bUJ;b[ij=b[ij-t;)js[n-l]=n-l;for(k=n-1;k>=();k—)if(js[k]!=k){t=b[k];b[k]=bUs[k]];bUs[k]]=t;}free(js);return(1);main(){inti;intrgaus
8、s(intn,doublea[][4],doubleb[]);staticdoublea[][4]={{0.1968,0.2071,1.2168,0.2271),{1.1161,0.1254,0.1397,0.1490},{0.2368,0.2471,0.256&1.2671},{0」582,1.1675,0」76&0.1871}};staticdoubleb[4]={1.7471,1.5471,1.8471,1.647