Simpson's Rule and Numerical Integration

Click For Summary

Discussion Overview

The discussion revolves around the implementation of Simpson's Rule for numerical integration in FORTRAN, specifically for the function y=x^2 over the interval from 1 to 3. Participants are addressing coding issues, program structure, and the requirements for summing values in the context of the integration process.

Discussion Character

  • Homework-related
  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant presents a FORTRAN program attempting to implement Simpson's Rule but encounters issues with the structure and logic of the code.
  • Another participant points out a mistake in the equation for h, suggesting it should be h=(Xmax-Xmin)/N.
  • Concerns are raised about the integration calculation, specifically regarding how to define and sum the odd and even indexed values (fodd and feven) within the loop.
  • A participant questions the appropriateness of the code provided, suggesting it does not conform to FORTRAN syntax and asks if simpler problems have been assigned prior to this task.
  • There is a discussion about the participant's familiarity with FORTRAN, with some indicating they have prior experience with dimension statements but lack knowledge on implementing loops for summation.
  • One participant expresses a need for help with the coding aspects, indicating uncertainty about how to proceed with the assignment.

Areas of Agreement / Disagreement

Participants do not reach a consensus on the correctness of the code or the approach to solving the problem. There are multiple competing views regarding the implementation details and the participant's level of understanding of FORTRAN.

Contextual Notes

Limitations include unclear definitions of variables such as fodd and feven, and the need for a proper understanding of FORTRAN syntax and programming structures to effectively implement the numerical integration.

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=\frac{h}{3} {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=\frac{(X<sub>max</sub>-X<sub>min</sub>)}{N}

oddweight=4

evenweight=2

DO i=1,256

I=\frac{h}{3} {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?
 
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
 
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
 
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
 
Nope it no but it the first one for integration and Simpsons rule
 
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?
 
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.
 

Similar threads

  • · Replies 7 ·
Replies
7
Views
2K
Replies
5
Views
4K
Replies
3
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
Replies
7
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 10 ·
Replies
10
Views
2K
  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K