Simpson's Rule and Numerical Integration

Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
11 replies · 5K views
Nandos
Messages
6
Reaction score
0
For this problem use Simpson's Rule with N=256 for numerical integration function is y=×^2
and the lower limit is 1 & 3 is the upper limit.

I=[itex]\frac{h}{3}[/itex] {fstart+fend+2Ʃfeven+4Ʃfodd}

Find the numerical integration, using FORTRAN

my solution follows like this:

Program SimpsonRule

IMPLICIT NONE

REAL :: Xmax, Xmin,h , y

INTEGER :: N

Xmax=1.0

Xmin=3.0

N256

contains

h=[itex]\frac{(X<sub>max</sub>-X<sub>min</sub>)}{N}[/itex]

oddweight=4

evenweight=2

DO i=1,256

I=[itex]\frac{h}{3}[/itex] {fstart+fend+2Ʃfeven+4Ʃfodd}


integrate y=x^2

print*,I

END DO

END Program SimpsonRule


comment

I have be told that the code must have subroutine, Do statement, function and call if statement.

my problem most start when i have to tell the computer to sum odd number and multiply by factor of 4 and sum the even number also multiply by factor of two.

the answer for the problem is 8.66667
 
Last edited:
Physics news on Phys.org
the equation BELOW CONTAINS suppose to be : h=(Xmax-Xmin)/N
 
Use CODE tags when entering source code to your post. This helps to preserve any spacing.

In the Loop, you can't just throw your I eqn. from the first part of the post directly into the middle of a loop and expect Fortran to make sense of it. More programming is required to obtain the proper calculation of the integral. How is the program to know what 'fodd' and 'feven' are?
 
This is the simpler problem that we need to work on before we do the hard problem, to make problem simple we suppose to find the integration of Y=×2 using Simpson's Rule on FORTRAN
 
Nope it no but it the first one for integration and Simpsons rule
 
Nope i don't know and can you please help me.