You are on page 1of 12

Applied research for numerical integration 23-02-2022

Numerical integration for 10-dimension definite integral in FORTRAN /


MATLAB
Extract:

Most of the books mention up to double integration. I needed triple integration to solve some
electromagnetic problem in 1997. I took up challenge to write, compile, & execute source codes up
to ten dimensions definite integral to solve problems in various industries. It took me nearly 5000
hours to overcome constraints, and reach my target in 2017. Now, source codes are also converted
in MATLAB.

Key words:

Multi-dimension definite integrals, source codes up to ten dimensions in FORTRAN 77 / MATLAB,


Research process, research questions, constraints, domain experts / mentors

I was stuck up, in 1997, to solve an electromagnetic problem having triple integral. I searched many
libraries but failed to get source code. Also, approached domain experts and they did not give
solution.

I was engaged in job (1997) when this idea struck to me. Since, I am passionate to solve
mathematical problems and I took up this challenge. I completed this task in four phases between
1997 to 2017.

Phase -1: 1997-99 (Two years)

 Survey / review of literature was done


 Research questions were identified
 Initially, source code was to be written for triple integral and subsequently for ten
dimensions integral
 Current status of various methods and future target was fixed
 Constraints were identified
 Additional resources were identified
 Need for domain expert / master minds could not be done in time
 During this period source code for triple integration could be successfully written and
further development work was stopped due to paucity of time.
 Research process was not documented and hence progress was poor and directionless. It
was decided to document the process as soon as possible. This phase compelled to
conceptualize the idea, conduct derivations with first principles, formulize derivations (put
things in proper sequence) etc.

Phase -2: 1999-2016 – No development work was done for 17 years

: Feb-May 2016 (4 months)

 Documenting the research process was given top priority. An exhaustive process was
documented in 17 steps.
Applied research for numerical integration 23-02-2022

 Due to definite guidelines laid down, source code for 3-6 dimensions definite integral could
easily be written & executed. Since pre-defined functions were used, length of source code
was huge. Please see below (based on Simpson’s 1/3 rd formula for integration)
o 1– dimension integral: 1-variable – 3 coefficients – 3 terms in formula
o 2- dimension integral: 2-variables – 9 coefficients – 9 terms in formula
o 3 – dimension integral – 3-variables – 27 coefficients – 27 terms
o 4 - dimension integral – 4-variables – 81 coefficients – 81 terms
o 5 - dimension integral – 5-variables – 243 coefficients – 243 terms

6 - dimension integral – 6-variables – 729 coefficients – 729 terms

o 7 - dimension integral – 7variables – 2187 coefficients – 2187 terms


o 8 - dimension integral – 8variables – 6521 coefficients – 6521 terms
o 9 - dimension integral – 9-variables – 19683 coefficients – 19683 terms
o 10 - dimension integral – 10-variables – 59049 coefficients – 59049 terms
 Since pre-defined functions increases, number of variables, coefficients, & terms increase.
The source code lines increases & compiler gives execution errors.
 One source code was split in to number of small code files. Each file was kept with about 100
functions depending upon variables. Code up to 6 dimensions could be run successfully.

Phase -3: May-June 2016 (2 months)

 Source code for 7 & 8 dimension were written. It again gave compilation error. I was
compelled to explore new method or new software to overcome the problem. How to
reduce code length?

Phase -4: June 2016 – Feb 2017 (8 months)

 I took time to evolve an iterative process to replace pr-defined functions. It was a right
decision. It drastically reduced code length and execution time also reduced.
 Source code for 9 & 10 dimension were written with iteration. It was run successively.
 Now, MATLAB was studied for some days to write the all above codes. I could succeed.
 A new challenge surfaced, how to store the coefficients as “data file”? Excel sheet solved this
problem.
 Now, pre-defined functions have been eliminates, iteration process is dsigned such a way to
call coefficients from data file. It helps in “protection of misuse” as well as reduces execution
time.

The source code for 10-dimension integral has been appended where “coefficients have to be called
from “data file”. For 10 dimension definite integral, 59049 coefficients have been stored in this data
file (264 kb).

If THIS ARTICLE IS ACCEPTED HERE, I WILL REVEAL RESEARCH PROCESS IN NEXT ARTICLE.

Thanks for your attention,

Nanak T. Dadlani

nanak.dadlani@gmail.com

INDIA
Applied research for numerical integration 23-02-2022
Applied research for numerical integration 23-02-2022

Source code for 10-dimension definite integral (FORTRAN)

C INTEG10.FOR (03-09-2021)

C Ref:- Numerical methods in Fortran

C J.M.McCormick and M.G.Salvadori

C Program no.9.9a/Page 316

C Theory on page 121

C 10-Dimension Definite Integral, TERMS=3^10=59049, SUMM(K), K=4

DIMENSION CO(59049),FZ(59049),SUMM(4),X(3),Y(3),Z(3),

1 W(3),V(3),U(3),S(3),R(3),Q(3),P(3)

NI=50

NO=66

OPEN (UNIT=50,FILE='INTEG10.TXT')

OPEN (UNIT=66,FILE='INTEG10.OP ')

DO 20 N=1,59049

READ(NI,*) CO(N)

WRITE (NO,010) CO(N)

010 FORMAT (16X,8HCO(N) = ,E10.4)

20 CONTINUE

C WRITE(*,*)'NUMX,NUMY,...,XA ,XB ,YA , YB... '

C WRITE(*,*)' 1 , 1 ,...,0 , 1 , 0 , 1... '

C WRITE(*,*)

C1 READ (*,*) NUMX,NUMY,....XA,XB,YA,YB,....


Applied research for numerical integration 23-02-2022

C WRITE(*,*)

C Limits:

NUMX=1

NUMY=1

NUMZ=1

NUMW=1

NUMV=1

NUMU=1

NUMS=1

NUMR=1

NUMQ=1

NUMP=1

XA=0.

XB=1.

YA=0.

YB=1.

ZA=0.

ZB=1.

WA=0.

WB=1.

VA=0.

VB=1.

UA=0.

UB=1.

SA=0.

SB=1.

RA=0.

RB=1.

QA=0.

QB=1.
Applied research for numerical integration 23-02-2022

PA=0.

PB=1.

PRINT 998, NUMX,NUMY,XA,XB,YA,YB

DO 200 K=1,2

NUMMX=NUMX*K

NUMMY=NUMY*K

NUMMZ=NUMZ*K

NUMMW=NUMW*K

NUMMV=NUMV*K

NUMMU=NUMU*K

NUMMS=NUMS*K

NUMMR=NUMR*K

NUMMQ=NUMQ*K

NUMMP=NUMP*K

XSTRIP=2.*NUMMX

YSTRIP=2.*NUMMY

ZSTRIP=2.*NUMMZ

WSTRIP=2.*NUMMW

VSTRIP=2.*NUMMV

USTRIP=2.*NUMMU

SSTRIP=2.*NUMMS

RSTRIP=2.*NUMMR

QSTRIP=2.*NUMMQ

PSTRIP=2.*NUMMP

XH=(XB-XA)/XSTRIP

YH=(YB-YA)/YSTRIP

ZH=(ZB-ZA)/ZSTRIP
Applied research for numerical integration 23-02-2022

WH=(WB-WA)/WSTRIP

VH=(VB-VA)/VSTRIP

UH=(UB-UA)/USTRIP

SH=(SB-SA)/SSTRIP

RH=(RB-RA)/RSTRIP

QH=(QB-QA)/QSTRIP

PH=(PB-PA)/PSTRIP

SUM=0.0

X(1)=XA

X(2)=X(1)+XH

X(3)=X(2)+XH

DO 100 I1=1,NUMMX

Y(1)=YA

Y(2)=Y(1)+YH

Y(3)=Y(2)+YH

DO 90 I2=1,NUMMY

Z(1)=ZA

Z(2)=Z(1)+ZH

Z(3)=Z(2)+ZH

DO 80 I3=1,NUMMZ

W(1)=WA

W(2)=W(1)+WH

W(3)=W(2)+WH

DO 70 I4=1,NUMMW

V(1)=VA
Applied research for numerical integration 23-02-2022

V(2)=V(1)+VH

V(3)=V(2)+VH

DO 60 I5=1,NUMMV

U(1)=UA

U(2)=U(1)+UH

U(3)=U(2)+UH

DO 50 I6=1,NUMMU

S(1)=SA

S(2)=S(1)+SH

S(3)=S(2)+SH

DO 40 I7=1,NUMMS

R(1)=RA

R(2)=R(1)+RH

R(3)=R(2)+RH

DO 30 I8=1,NUMMR

Q(1)=QA

Q(2)=Q(1)+QH

Q(3)=Q(2)+QH

DO 27 I9=1,NUMMQ

P(1)=PA

P(2)=P(1)+PH

P(3)=P(2)+PH

DO 25 I10=1,NUMMP

KOUNT=0

DO 111 J1= 1,3


Applied research for numerical integration 23-02-2022

DO 112 J2=1,3

DO 113 J3=1,3

DO 114 J4=1,3

DO 115 J5=1,3

DO 116 J6=1,3

DO 117 J7=1,3

DO 118 J8=1,3

DO 119 J9=1,3

DO 120 J10=1,3

KOUNT=KOUNT+1

FN=F(X(J1),Y(J2),Z(J3),W(J4),V(J5),U(J6),S(J7),R(J8),

1 Q(J9),P(J10))

FZ(KOUNT)=FN

SUM=SUM+(XH*YH*ZH*WH*VH*UH*SH*RH*QH*PH/59049)*

1 FZ(KOUNT)*CO(KOUNT)

120 CONTINUE

119 CONTINUE

118 CONTINUE

117 CONTINUE

116 CONTINUE

115 CONTINUE

114 CONTINUE

113 CONTINUE

112 CONTINUE

111 CONTINUE

C DO 301 KOUNT=1,59049

C301 PRINT 300,FZ(KOUNT)

C300 FORMAT (16X,F10.5)

C
Applied research for numerical integration 23-02-2022

P(1)=P(3)

P(2)=P(1)+PH

25 P(3)=P(2)+PH

Q(1)=Q(3)

Q(2)=Q(1)+QH

27 Q(3)=Q(2)+QH

R(1)=R(3)

R(2)=R(1)+RH

30 R(3)=R(2)+RH

S(1)=S(3)

S(2)=S(1)+SH

40 S(3)=S(2)+SH

U(1)=U(3)

U(2)=U(1)+UH

50 U(3)=U(2)+UH

V(1)=V(3)

V(2)=V(1)+VH

60 V(3)=V(2)+VH

W(1)=W(3)

W(2)=W(1)+WH

70 W(3)=W(2)+WH

Z(1)=Z(3)

Z(2)=Z(1)+ZH
Applied research for numerical integration 23-02-2022

80 Z(3)=Z(2)+ZH

Y(1)=Y(3)

Y(2)=Y(1)+YH

90 Y(3)=Y(2)+YH

X(1)=X(3)

X(2)=X(1)+XH

100 X(3)=X(2)+XH

PRINT 997,K,XH,YH,SUM

200 SUMM(K)=SUM

C INTRODUCE STATEMENT "GO TO 1" TO SEE VARIOUS OUTPUTS BY

C CHANGING INPUT VALUES

C GO TO 1

997 FORMAT (I18,2F10.5,E17.7)

998 FORMAT (//23X,26HRESULTS FROM PROGRAM 9.9A

$ //25X,21HLIMITS OF INTEGRATION

$ / 16X,7HNUMX = ,I4,4X,7HNUMY = ,I4

$ /16X,4HXA = ,E14.7,4X,4HXB = ,E14.7 / 16X,4HYA = ,E14.7,

$ 4X,4HYB = ,E14.7/

$ //17X,1HK ,6X,2HXH ,8X,2HYH ,8X,8HINTEGRAL)

END

C Ex-1

C Limits: XA=0, XB=1., YA=0 ,YB=1.,ZA=0., ZB=1.,WA=0, WB=1.

C VA=0.,VB=1., UA=0.,UB=1.,SA=0., SB=1.,RA=0.,RB=1.


Applied research for numerical integration 23-02-2022

C NUMX=1, NUMY=1, NUMZ=1, NUMW=1....

C I= 25.833 ..MATLAB (I=25.833,@ K= 1; I=22.4 @ K=2)

FUNCTION F(X,Y,Z,W,V,U,S,R,Q,P)

F=(X+Y+Z+W+V+U+S+R+Q+P)**2

RETURN

END

You might also like