7 楼
剑气v纵横 [专家分:0] 发布于 2012-06-24 01:19:00
USE MSFLIB
INTEGER(2) result
INTEGER(4) color
INTEGER(1),TARGET::STYLE(8)&
/#80,#40,#20,#10,#08,#04,#02,#01/
INTEGER(1),POINTER::PTR(:)
TYPE(xycoord) XY
TYPE(WINDOWCONFIG)WC
PARAMETER(N=3)
REAL,DIMENSION(N,N)::A,B
REAL,DIMENSION(N)::P,Q,E,F
REAL NORM1,NORM2,COND
WC.NUMXPIXELS=800
WC.NUMYPIXELS=600
result=INITIALIZEFONTS() !初始化前景
result=SETFONT('Arial''h18w10i') !设置前景字体
color=SETTEXTCOLORRGB(#0000FF) !设置字体颜色为红色
status=SETBKCOLORRGB(#ffffff) !设置背景为白色
CALL CLEARSCREEN($GCLEARSCREEN)
color=SETCOLORRGB(#000000) !设置当前绘图颜色为蓝色(坐标系)
OPEN(1,FILE='XISHU.TXT')
READ(1,*)((A(I,J),J=1,N),I=1,N)
READ(1,*)(P(I),I=1,N)
READ(1,*)(Q(I),I=1,N)
CLOSE(1)
B=A
CALL TRIANGLE(A,P,E,N)
PRINT *,"向量元素b3为0.52时,方程组的解是:"
WRITE(*,100)(E(I),I=1,N)
CALL TRIANGLE(A,Q,F,N)
PRINT *,"向量元素b3为0.53时,方程组的解是:"
WRITE(*,100)(F(I),I=1,N)
100 FORMAT(10X,F8.5)
CALL FANSHU(B,N,NORM1)
CALL GAUSSJ(B,N)
CALL FANSHU(B,N,NORM2)
COND=NORM1*NORM2
PRINT *,"矩阵A的条件数为:"
WRITE(*,200)COND
200 FORMAT(8X,F12.5)
Y1=-E(1)*10
Y2=-E(2)*10
Y3=-E(3)*10
Y4=-F(1)*10
Y5=-F(2)*10
Y6=-F(3)*10
CALL SETVIEWORG(200,550,XY) !改变视口坐标原点位置
CALL MOVETO(INT2(-50),INT2(0),XY) !移动到指定位置
result=LINETO(INT2(800),INT2(0))
CALL MOVETO(INT2(0),INT2(200),XY) !移动到指定位置
result=LINETO(INT2(0),INT2(-200))
CALL MOVETO(0,INT2(5),XY)
CALL OUTGTEXT("0")
CALL MOVETO(100,INT2(5),XY)
CALL OUTGTEXT("1")
CALL MOVETO(200,INT2(5),XY)
CALL OUTGTEXT("2")
CALL MOVETO(300,INT2(5),XY)
CALL OUTGTEXT("3")
CALL MOVETO(400,INT2(5),XY)
CALL OUTGTEXT("4")
CALL MOVETO(500,INT2(5),XY)
CALL OUTGTEXT("5")
CALL MOVETO(600,INT2(5),XY)
CALL OUTGTEXT("6")
CALL MOVETO(700,INT2(5),XY)
CALL OUTGTEXT("7")
CALL MOVETO(-50,200,XY)
CALL OUTGTEXT("-20")
CALL MOVETO(-50,150,XY)
CALL OUTGTEXT("-15")
CALL MOVETO(-50,100,XY)
CALL OUTGTEXT("-10")
CALL MOVETO(-50,50,XY)
CALL OUTGTEXT("-5")
CALL MOVETO(-50,0,XY)
CALL OUTGTEXT("0")
CALL MOVETO(-50,-50,XY)
CALL OUTGTEXT("5")
CALL MOVETO(-50,-100,XY)
CALL OUTGTEXT("10")
CALL MOVETO(-50,-150,XY)
CALL OUTGTEXT("15")
CALL MOVETO(-50,-200,XY)
CALL OUTGTEXT("20")
RESULT=SETCOLORRGB(#000000) !设置前景为绿色
result=RECTANGLE($GBORDER,100,Y1,200,0)
result=RECTANGLE($GBORDER,300,Y2,400,0)
result=RECTANGLE($GBORDER,500,Y3,600,0)
PTR=>STYLE
CALL SETFILLMASK(PTR)
result=RECTANGLE($GFILLINTERIOR,200,Y4,300,0)
result=RECTANGLE($GFILLINTERIOR,400,Y5,500,0)
result=RECTANGLE($GFILLINTERIOR,600,Y6,700,0)
end
!高斯消去法
SUBROUTINE GAUSSJ(A,N)
INTEGER N,NMAX
REAL A(N,N),B(N)
PARAMETER (NMAX=50)
INTEGER I,ICOL,IROW,J,K,L,L1,INDXC(NMAX),INDXR(NMAX),IPIV(NMAX)
REAL BIG,DUM,PIVINV
DO J=1,N
IPIV(J)=0
ENDDO
DO I=1,N
BIG=0
DO J=1,N
IF(IPIV(J)/=1)THEN
DO K=1,N
IF(IPIV(K)==0)THEN
IF(ABS(A(J,K))>=BIG)THEN
BIG=ABS(A(J,K))
IROW=J
ICOL=K
ENDIF
ELSE
IF(IPIV(K)>1)THEN
PAUSE 'SINGULAR MATRIX IN GAUSSJ'
ENDIF
ENDIF
ENDDO
ENDIF
ENDDO
IPIV(ICOL)=IPIV(ICOL)+1
IF(IROW/=ICOL)THEN
DO L=1,N
DUM=A(IROW,L)
A(IROW,L)=A(ICOL,L)
A(ICOL,L)=DUM
ENDDO
DUM=B(IROW)
B(IROW)=B(ICOL)
B(ICOL)=DUM
ENDIF
INDXR(I)=IROW
INDXC(I)=ICOL
IF(A(ICOL,ICOL)==0.)PAUSE 'SINGULAR MATRIX IN GAUSSJ'
PIVINV=1./A(ICOL,ICOL)
A(ICOL,ICOL)=1
DO L=1,N
A(ICOL,L)=A(ICOL,L)*PIVINV
ENDDO
B(ICOL)=B(ICOL)*PIVINV
DO L1=1,N
IF(L1/=ICOL)THEN
DUM=A(L1,ICOL)
A(L1,ICOL)=0
DO L=1,N
A(L1,L)=A(L1,L)-A(ICOL,L)*DUM
ENDDO
B(L1)=B(L1)-B(ICOL)*DUM
ENDIF
ENDDO
DO L=N,1,-1
IF(INDXR(L)/=INDXC(L))THEN
DO K=1,N
DUM=A(K,INDXR(L))
A(K,INDXR(L))=A(K,INDXC(L))
A(K,INDXC(L))=DUM
ENDDO
ENDIF
ENDDO
ENDDO
END
8 楼
剑气v纵横 [专家分:0] 发布于 2012-06-24 01:19:00
!求A的范数AM
SUBROUTINE FANSHU(B,N,AM)
DIMENSION B(N,N),D(N)
REAL B,D,AM
DO J=1,N
D(J)=0.0
DO I=1,N
D(J)=D(J)+ABS(B(I,J))
ENDDO
ENDDO
AM=0.0
DO J=1,N
IF(AM<D(J)) AM=D(J)
ENDDO
PRINT *,"范数AM为:"
WRITE(*,300)AM
300 FORMAT(10X,F12.5)
END
!求方程组的解
SUBROUTINE TRIANGLE(A,M,E,N)
INTEGER S,P
REAL,DIMENSION(N,N)::A,B,C
REAL,DIMENSION(N)::M,D,E
DO I=1,N
C(1,I)=A(1,I)
B(I+1,1)=A(I+1,1)/C(1,1)
ENDDO
DO I=2,N
DO J=I,N
C(I,J)=A(I,J)
DO S=1,I-1
C(I,J)=C(I,J)-B(I,S)*C(S,J)
ENDDO
ENDDO
J=I
DO P=J,N
B(P+1,J)=A(P+1,J)/C(J,J)
DO S=1,J-1
B(P+1,J)=B(P+1,J)-B(P+1,S)*C(S,J)/C(J,J)
ENDDO
ENDDO
ENDDO
DO I=2,N
DO J=1,I-1
C(I,J)=0
ENDDO
ENDDO
DO J=1,N
DO I=1,J
IF(I==J)THEN
B(I,J)=1
ELSE
B(I,J)=0
ENDIF
ENDDO
ENDDO
D(1)=M(1)
DO I=2,N
D(I)=M(I)
DO S=1,I-1
D(I)=D(I)-B(I,S)*D(S)
ENDDO
ENDDO
E(N)=D(N)/C(N,N)
DO I=N-1,1,-1
E(I)=D(I)/C(I,I)
DO S=I+1,N
E(I)=E(I)-C(I,S)*E(S)/C(I,I)
ENDDO
ENDDO
END