Simpson's Rule and Numerical Integration

In summary, Simpson's Rule with N=256 for numerical integration function is y=×^2 and the lower limit is 1 & 3 is the upper limit. The program uses FORTRAN and calculates the integral of y=x^2.
  • #1
Nandos
6
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{(Xmax-Xmin)}{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
  • #2
the equation BELOW CONTAINS suppose to be : h=(Xmax-Xmin)/N
 
  • #3
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?
 
  • #4
Hi Nandos. Welcome to Physics Forums.

I don't know what this code is that you have written, but it definitely is not FORTRAN. Have you been assigned any simpler problems to work on before you advanced to a program like this?

Chet
 
  • #5
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
 
  • #6
Nandos said:
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

Are you saying that this is the first FORTRAN program you will have ever written?

Chet
 
  • #7
Nope it no but it the first one for integration and Simpsons rule
 
  • #8
Nandos said:
Nope it no but it the first one for integration and Simpsons rule
So you are familiar with Dimension statements, and have used them before?
 
  • #9
Yes we have
 
  • #10
Nandos said:
Yes we have
Then at least the function F should be dimensioned in your FORTRAN program. Do you know how to set up a do loop to carry out a sum on a subscripted variable?
 
  • #11
Nope i don't know and can you please help me.
 
  • #12
Nandos said:
Nope i don't know and can you please help me.
You need to get yourself a textbook on FORTRAN and do a little studying. The information you need to do this assignment is a little to extensive for a format like PF.
 

Related to Simpson's Rule and Numerical Integration

What is Simpson's Rule?

Simpson's Rule is a method used for numerical integration, which is a technique for estimating the area under a curve. Specifically, Simpson's Rule uses parabolic curves to approximate the area under a function, resulting in a more accurate estimation than other methods such as the trapezoidal rule.

How is Simpson's Rule calculated?

To calculate Simpson's Rule, the interval of the function must be divided into an even number of subintervals. Then, the rule involves taking the weighted average of the values at the endpoints and the midpoint of each subinterval, using a specific formula. This process is repeated for each subinterval, and the results are summed to approximate the area under the curve.

What is numerical integration used for?

Numerical integration is used when the area under a curve cannot be easily calculated using traditional methods. It is often used in scientific and engineering fields to estimate solutions to problems involving continuous functions, such as calculating the volume of an irregularly shaped object or the trajectory of a moving object.

What are the advantages of using Simpson's Rule?

Simpson's Rule is advantageous because it provides a more accurate estimation of the area under a curve compared to other numerical integration methods, such as the trapezoidal rule. It also requires fewer subintervals to achieve a similar level of accuracy, making it a more efficient option for computation.

Are there any limitations to using Simpson's Rule?

While Simpson's Rule is a more accurate method of numerical integration compared to others, it is not suitable for all functions. It works best for smooth, continuous functions and may produce inaccurate results for functions with discontinuities or sharp corners. Additionally, it can be time-consuming to compute for functions with a large number of subintervals.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
3
Views
833
  • Engineering and Comp Sci Homework Help
Replies
7
Views
1K
Replies
2
Views
424
Replies
3
Views
974
  • Advanced Physics Homework Help
Replies
7
Views
1K
  • Set Theory, Logic, Probability, Statistics
Replies
10
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
5
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
Replies
6
Views
1K
Back
Top