Report5 Jacobi 반복법, Gauss-seided 반복법 2011, Feb 05 #include <iostream></p> // jacobi 반öY복¬©ö법öy float A[4][5]={10,-1,2,0,6, -1,11,-1,3,25, 2,-1,10,-1,-11, 0,3,-1,8,15}; class function{ public: float x1; float x2; float x3; float x4; float x5; float x1p; float x2p; float x3p; float x4p; int position; void setfunction(float _x1,float _x2,float _x3,float _x4,float _x5,int _position) { x1=_x1; x2=_x2; x3=_x3; x4=_x4; x5=_x5; position = _position; } float return_Value(float p1,float p2,float p3,float p4) { if(position == 1) { return ((x2*p2+x3*p3+x4*p4)-x5)/x1*(-1); } else if(position == 2) { return ((x1*p1+x3*p3+x4*p4)-x5)/x2*(-1); } else if(position ==3) { return ((x1*p1+x2*p2+x4*p4)-x5)/x3*(-1); } else if(position ==4) { return ((x1*p1+x2*p2+x3*p3)-x5)/x4*(-1); } } }; int main() { int inputx=4; int inputy=5; float return_x=0; float return_y=0; float return_z=0; float return_v=0; for(int i=0;i<inputx;i++) { float temp=0; for(int j=0;j<inputy-1;j++) { if(i!=j) { temp+=abs(A[i][j]); } } if(abs(A[i][i])<abs(temp)) { printf("강Æ¡©대¥e각Æ¡Ë 행a렬¤A이I 아ú¨¡님¥O."); return 0; } } //강Æ¡©대¥e각Æ¡Ë 행a렬¤A임O 계Æe속ùO 진©ª행a; //한N줄U 식öA을¡í 객Æ¢¥체¨ù화¡© 함O. function fun[4]; for(int i=0;i<4;i++) { fun[i].setfunction(A[i][0],A[i][1],A[i][2],A[i][3],A[i][4],i+1); } for(int i=0;i<20;i++) { printf("step %d\n",i+1); float temp1=0; float temp2=0; float temp3=0; float temp4=0; for(int j=0;j<4;j++) { if(j==0) { temp1 = fun[j].return_Value(return_x,return_y,return_z,return_v); printf("x : %f ",temp1); } if(j==1) { temp2 = fun[j].return_Value(return_x,return_y,return_z,return_v); printf("y : %f ",temp2); } if(j==2) { temp3 = fun[j].return_Value(return_x,return_y,return_z,return_v); printf("z : %f ",temp3); } if(j==3) { temp4 = fun[j].return_Value(return_x,return_y,return_z,return_v); printf("v : %f ",temp4); } } return_x=temp1; return_y=temp2; return_z=temp3; return_v=temp4; printf("\n"); } return 0; } </textarea> </div> </div> #include <iostream></p> //gauss-seided 방ö©¡법öy float A[4][5]={10,-1,2,0,6, -1,11,-1,3,25, 2,-1,10,-1,-11, 0,3,-1,8,15}; class function{ public: float x1; float x2; float x3; float x4; float x5; float x1p; float x2p; float x3p; float x4p; int position; void setfunction(float _x1,float _x2,float _x3,float _x4,float _x5,int _position) { x1=_x1; x2=_x2; x3=_x3; x4=_x4; x5=_x5; position = _position; } float return_Value(float p1,float p2,float p3,float p4) { if(position == 1) { return ((x2*p2+x3*p3+x4*p4)-x5)/x1*(-1); } else if(position == 2) { return ((x1*p1+x3*p3+x4*p4)-x5)/x2*(-1); } else if(position ==3) { return ((x1*p1+x2*p2+x4*p4)-x5)/x3*(-1); } else if(position ==4) { return ((x1*p1+x2*p2+x3*p3)-x5)/x4*(-1); } } }; int main() { int inputx=4; int inputy=5; float return_x=0; float return_y=0; float return_z=0; float return_v=0; for(int i=0;i<inputx;i++) { float temp=0; for(int j=0;j<inputy-1;j++) { if(i!=j) { temp+=abs(A[i][j]); } } if(abs(A[i][i])<abs(temp)) { printf("강Æ¡©대¥e각Æ¡Ë 행a렬¤A이I 아ú¨¡님¥O."); return 0; } } //강Æ¡©대¥e각Æ¡Ë 행a렬¤A임O 계Æe속ùO 진©ª행a; //한N줄U 식öA을¡í 객Æ¢¥체¨ù화¡© 함O. function fun[4]; for(int i=0;i<4;i++) { fun[i].setfunction(A[i][0],A[i][1],A[i][2],A[i][3],A[i][4],i+1); } for(int i=0;i<20;i++) { printf("step %d\n",i+1); for(int j=0;j<4;j++) { if(j==0) { return_x = fun[j].return_Value(return_x,return_y,return_z,return_v); printf("x : %f ",return_x); } if(j==1) { return_y = fun[j].return_Value(return_x,return_y,return_z,return_v); printf("y : %f ",return_y); } if(j==2) { return_z = fun[j].return_Value(return_x,return_y,return_z,return_v); printf("z : %f ",return_z); } if(j==3) { return_v = fun[j].return_Value(return_x,return_y,return_z,return_v); printf("v : %f ",return_v); } } printf("\n"); } return 0; } </textarea> </div> Please enable JavaScript to view the comments powered by Disqus.