A Sample Program Code in FORTRAN:



program integrate_i
!uses internal function
integer::i,nd=25
real,dimension(25)::x,y
real::numerical,analytic
x=(/(i,i=1,nd)/)
y=log(x)/x
numerical=(x(2)-x(1))*SIMPSON()
analytic=0.5*(log(x(nd)**2-log(x(1))**2)
print*,'The integral of [log(x)/x] for x=',x(1),'to',x(nd),'is:'
print*,nemerical,'by Simpson's Rule, using',nd,'meshpoints'
print*,analytic,'analytically'
CONTAINS	!the function SIMPSON
REAL FUNCTION SIMPSON()
!Numerical integration by Simpson's Rule
real::subsum ; integer::i
subsum=0
do i=1,nd-2,2
subsum=subsum+y(i)+4*y(i+1)+y(i+2)
end do
SIMPSON=subsum/3
RETURN
END FUNCTION SIMPSON
end program integrate_i


Finite difference formulae and Simpson's Rule: (Mathematical background)
Many solutions may be available as tabulated data given at specific incremental values. Suppose however, that we wish to find a specific value that falls between 2 tabulated values. In order to integrate or differentiate a tabulated function one can use finite difference formulae that approximate the function by straight lines or a quadratic between adjacent tabulated values. The accuracy of the results depends on the density of the tabulated points, the 'mesh size'. Simpson's formula requires an odd number of tabulation points to work correctly.

About this sample program:
Several short functions like SIMPSON can be conveniently accommodated within the main program. The command CONTAINS separates them from the statements of the main program. Placed like that they are internal functions. To the compiler, a program containing just internal fuctions is only one segment.

As far as the flow of instructions of the main program is concerned, everything between the command CONTAINS and the END FUNCTION statement is skipped. As with external functions, the instructions that are inside the internal function are only carried out when the function is called.

Just as for external functions, variables that are declared within an internal function are 'local' to that function and do not affect any variables in the main program even if they have the same name. But, in contrast to external functions, the internal function has access to all the variables defined in the main program. Therefore, the example function SIMPSON does not require any arguments, which is indicated by empty brackets ().

Internal functions that are in the same argument can call each other but they cannot be called from within other program segments.


General mathematical and scientific programming links:
Scientific computation course at NYU Mathematical programming in chemistry Statistical calculators collection


Contents Courses Frames demo Downloads More links Contact form Psend kept free because of these great sponsors.a..

Other Sponsors

electrical connectors, Mangosteen Juice, real estate short sale, Jupiter FL real estate,

Furniture Markdown

Great Deals on furniture - Free Shipping!
Discount Furniture
Daybeds
Metal Beds
Platform Beds
Futons

Y-Net Wireless Internet

Denver area high speed wireless privider.
Colorado High Speed Internet, Wireless Internet Denver, VOIP Denver CO, T1 provider Denver, Denver Wireless ISP , Denver Internet Access,

Dog House Technologies

Doghouse Techonologies is located in Tampa Bay FL and offer professional web design, ecommerce development and custom application design for the internet.
Tampa Bay Web Design, E-Commerce Web Design, Tampa Bay Search Engine Marketing, Tampa Web Hosting, Florida Web Design, Custom Application Development, Search Engine Optimization,

/hosting.asp">Tampa Web Hosting and Florida Web Design This site hosted curtosy of Psend.com's Free Web Hosting. Psend is a division of Telos Online, Inc. Psend kept free because of these great sponsors.a..

Other Sponsors

electrical connectors, Mangosteen Juice, real estate short sale, Jupiter FL real estate,

Furniture Markdown

Great Deals on furniture - Free Shipping!
Discount Furniture
Daybeds
Metal Beds
Platform Beds
Futons

Y-Net Wireless Internet

Denver area high speed wireless privider.
Colorado High Speed Internet, Wireless Internet Denver, VOIP Denver CO, T1 provider Denver, Denver Wireless ISP , Denver Internet Access,

Dog House Technologies

Doghouse Techonologies is located in Tampa Bay FL and offer professional web design, ecommerce development and custom application design for the internet.
Tampa Bay Web Design, E-Commerce Web Design, Tampa Bay Search Engine Marketing, Tampa Web Hosting, Florida Web Design, Custom Application Development, Search Engine Optimization,