How to Write a Program to Solve an Integral with Subintervals?

  • Context: Undergrad 
  • Thread starter Thread starter bethi309
  • Start date Start date
  • Tags Tags
    Integral Program
Click For Summary

Discussion Overview

The discussion revolves around writing a program to solve a definite integral using numerical methods, specifically focusing on how to implement this with a specified number of subintervals. The integral in question is \(\int^{1}_{0} \frac{4}{1 + x^{2}}dx\), which is known to yield the result of pi. Participants explore various programming approaches and methods for numerical integration.

Discussion Character

  • Technical explanation
  • Mathematical reasoning
  • Homework-related

Main Points Raised

  • One participant seeks guidance on writing a program to numerically solve the integral using a large number of subintervals.
  • Another participant suggests using the definition of the integral by partitioning the interval and summing the products of function values and interval widths.
  • A third participant questions whether the request is for numerical integration or algebraic integration, noting that numerical integration is easier to implement.
  • A later reply indicates that the initial participant is interested in numerical integration and has made progress using Visual Basic, while also inquiring about the concept of "para comparison."

Areas of Agreement / Disagreement

Participants generally agree on the approach to numerical integration, but there is a lack of consensus on the specific methods to use, such as whether to apply Simpson's rule or other techniques. The discussion remains open regarding the concept of "para comparison."

Contextual Notes

There are unresolved details regarding the implementation specifics, such as the choice of numerical method and the handling of function evaluations within the intervals. The discussion does not clarify the definition or application of "para comparison."

Who May Find This Useful

This discussion may be useful for individuals interested in numerical methods for integration, programming in various languages, or those seeking to understand different approaches to solving integrals computationally.

bethi309
Messages
2
Reaction score
0
I'm wondering if anyone know how to write a program to solve a simple integral when input a number of subintervals. this program can be written with any language, C++, java, fortran, C, etc...

this is an obvious integral to solve, but i have no idea how to write a program for it. the answer is pi, but how to write a program to get this answer when entered a subinterval of 400,000,000?

[tex]\int^{1}_{0}[/tex] [tex]\frac{4}{1 + x^{2}}[/tex]dx
 
Physics news on Phys.org
Just use the (approximate) definition of the integral. Partition the set [0,1] into however many intervals of width dx. Then take a value of f(x) within each interval (it can be in middle or endpoints or wherever in the interval), and multiple it to dx. Then sum them all up for each interval. It should look something like this:

a=0; b=1; dx=(b-a)/n; sum=0;
for(i=a, i<b, i+=dx)
{
sum=sum+f(i)*dx;
}

In this case I am taking the values at the left of the interval and n is the number of subintervals. I hope I didn't make a mistake but it should look something like that.
 
Are you asking for a program to do a numerical integration (very easy) or a program to do an "algebraic" integral (very hard)?

Variety gave an example of a simple example of a numerical integration, though using Simpson's rule is not really harder to program and is faster for a given accuracy.
 
I was just asking for a program to do a numerical integration. variety gave me an idea of what to do, I got it figured out on visual basics. I'm wondering if there's a way to do this using para comparison.
 
What is para comparison if that is not a rude question ?
 

Similar threads

  • · Replies 16 ·
Replies
16
Views
4K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 11 ·
Replies
11
Views
3K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 8 ·
Replies
8
Views
4K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 17 ·
Replies
17
Views
6K
  • · Replies 8 ·
Replies
8
Views
2K