PROGRAM MYPROG INTEGER NX, NY ! Variables to hold number of intervals in each direction REAL XSTART, XEND ! Variables defining the interval in x-direction REAL YSTART, YEND ! Variables defining the inverval in y-direction REAL DX, DY REAL PHI(21,21) CALL DEFINEMATRIX(XSTART, XEND, YSTART, YEND, NX, NY) ! Lets the user specify the interval for which the problem will be solved, and the number of intervals for discretisation DX=(XEND-XSTART)/NX DY=(YEND-YSTART)/NY CALL ENTERBOUNDARYVALUES(PHI,XSTART,DX,NX,YSTART,DY,NY) WRITE(*,*) ' xs ys ', PHI(1,1) WRITE(*,*) ' xs+d ys ', PHI(1,1+NX) WRITE(*,*) ' xs ys+d ', PHI(1+NY,1) WRITE(*,*) ' xs+d ys+d ', PHI(1+NY,1+NX) END PROGRAM !---------------------------------! SUBROUTINE DEFINEMATRIX(XS,XE,YS,YE,NX,NY) REAL XS, XE, YS, YE INTEGER NX, NY write(*,*) 'Choose the interval in x-direction for which you wish to solve the problem. Input format ' CALL READINTERVAL(XS, XE) ! Prompt user to input x-interval write(*,*) 'Choose the interval in y-direction for which you wish to solve the problem. Input format ' CALL READINTERVAL(YS, YE) ! Prompt user to input y-interval write(*,*) 'Specify number of intervals you want in the x-direction' read(*,*) NX write(*,*) 'Specify number of intervals you want in the y-direction' read(*,*) NY END SUBROUTINE !----------------------------------! SUBROUTINE READINTERVAL(START, END) REAL START, END read(*,*) START, END ! Assignes the values to the corresponding variables END SUBROUTINE !----------------------------------! FUNCTION G(X,Y) REAL X,Y REAL G G=1 RETURN END FUNCTION !----------------------------------! REAL FUNCTION PHIBOUNDARY(X,Y) REAL X, Y PHIBOUNDARY=(X**2+Y**2)/4.0 RETURN END FUNCTION !----------------------------------! SUBROUTINE ENTERBOUNDARYVALUES(PHI, XSTART, DX, NX, YSTART, DY, NY) REAL PHI(21,21) REAL XSTART, DX, YSTART, DY INTEGER NX, NY INTEGER COL INTEGER ROW DO WHILE(COL<=NX+1) PHI(1,COL)=PHIBOUNDARY(XSTART+(COL-1)*DX,YSTART) PHI(NY+1,COL)=PHIBOUNDARY(XSTART+(COL-1)*DX,YSTART+NY*DY) COL=COL+1 END DO ROW=2 DO WHILE(ROW<=NY)!DENNE GÅR FRA 2 TIL OG MED NY, DA 1 OG NY+1 ER FYLT UT AV LØKKEN OVER PHI(ROW,1)=PHIBOUNDARY(XSTART,YSTART+(ROW-1)*DY) PHI(ROW,NX+1)=PHIBOUNDARY(XSTART+NX*DX,YSTART+(ROW-1)*DY) ROW=ROW+1 END DO END SUBROUTINE