資源描述:
《數(shù)值計(jì)算-方程組》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在工程資料-天天文庫。
1、分別用雅可比、高斯塞達(dá)爾、超松弛法解方程組。精度:0.0015*xl+2*x2+x*3二12-xl+x*2+2*x3二202*xl?*3x2+10*x3二31:雅可比迭代法(Jacobi):/*5*xl4-2*x2+x*3=-12-xl+x*2+2*x3二202*xl-*3x2+10*x3=3旬#include"math.h"#include"stdio.h"main(){doublea[3][3]={{5.0,2.0,1.0},{?1.0,4.0,2.0},{2.0,-3.0,10.0}};doublex[3]={0.0,0.0,0.0},y[3],b[3]
2、={?12.0,20.0,3.0};doubleeps=0.001,e,q,t,s;inti,j,k,N=0;e=eps+1.0;while(e>=eps){N++;e=0.0;for(k=0;k<3;k++)y[k]=x[k];for(i=0;i<3;i++){t=x[i];s=0.0;for(j=0;j<3;j++)if(j匸i)s=s+a[i][j]*y[j];x[i]=(b[i]-s)/a[i][i];printf(ux%2d(%2d)=%fi+1,N,x[i]);q=fabs(x[i]-t);if(q>e)e=q;}printf(””);X1<
3、1>-2.400000X2<1>5?000000X3<1>0.300000X1<2>-4.460000X2<2>4.250000X3<2>2.280000X1<3>-4.556000X2<3>2.745000X3<3>2.467000X1<4>-3.991400X2<4>2.627500X3<4>2.034700X1<5〉-3.857940X2<5〉2.984800X3<5〉1.886530X1<6〉-3.971226X2<6〉3.092250X3<6〉1.967028X1<7>-4.030306X2<7>3.023680X3<7>2.021920X1<8>-
4、4.013856X2<8>2.981464X3<8>2.013165X1<9〉-3.995218X2<9〉2.989954X3<9〉1.997210X1<10>-3.995423X2<10>3.002590X3<10>1.996030X1<11>-4.000242X2<11>3.003129X3<11>1.999862X1<12>-4.001224X2<12>3.000009X3<12>2.000987X1<13>-4.000201X2<13>2.999200X3<13>2.000247X1<14>-3.999730X2<14>2.999826X3<14>1.
5、999800c初:學(xué)習(xí)文件數(shù)值計(jì)算2DebugJacobi.exe*Pressanykeytocontinue2:高斯賽德爾迭代法(G?S)5*xl4-2*x2+x*3=-12-xl+x*2+2*x3=202*xl-*3x2+10*x3=3旬#include"math.h"#include"stdio.h”main(){doublea[3][3]={{5.0,2.0,1.0},{-1.0,4.0,2.0},{2.0,-3.0,10.0}};doublex[3]={0.0,0.0,0.0},b[3]={?12.0,20.0,3.0);doubleep
6、s=0.001,e,q,t,s;inti,j,k,N=O;e=eps+1.0;while(e>=eps){N++;e=0.0;for(i=0;i<3;i++){t=x[i];s=0.0;for(j=0;j<3;j++)if(j匸i)s=s+a[i][j]*x[j];x[i]=(b[i]-s)/a[i][i];printf(ux%2d(%2d)=%r,i+1,N,x[i]);q=fabs(x[i]-t);訐(q>e)e=q;}printfCVn");}}X1<1>-2?400000X2<1>4.400000X3<1>X1<2>-4.580000X2<2>2.80
7、5000X3<2>X1<3>-3.933500X2<3>2.987875X3<3>X1<4>-3.991763X2<4>3.010528X3<4>X1<5〉-4.004513X2<5〉2.998116X3<5〉X1<6〉-3.999314X2<6〉3?000003X3<6〉X1<7>-3.999974X2<7>3?000075X3<7>c八學(xué)習(xí)文件數(shù)值計(jì)算2DebugG-S.exe"2.1000002.0575001.9830632.0015112.0003381.9998642.00001?Pressanykeytocontinue3:逐次超松弛迭
8、代法(SOR):嚴(yán)5*xl+2*x2+