A program to solve an integral

In summary, the conversation is about writing a program to solve a simple integral when given a number of subintervals. The answer is pi and the program can be written in various languages. One person suggests using the approximate definition of the integral and partitioning the set [0,1] into intervals to find the sum. Another person suggests using Simpson's rule for faster and more accurate results. The original person asking the question was able to figure out a solution using visual basics and is now wondering if there is a way to do it using "para comparison," though it is unclear what this means.
  • #1
bethi309
2
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
  • #2
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.
 
  • #3
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.
 
  • #4
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.
 
  • #5
What is para comparison if that is not a rude question ?
 

1. What is an integral?

An integral is a mathematical concept that represents the area under a curve. It is commonly used to solve problems involving continuous quantities, such as finding the total distance traveled by an object over a period of time.

2. Why do we need a program to solve integrals?

Integrals can be very complex and time-consuming to solve by hand. A program can perform the necessary calculations quickly and accurately, saving time and effort for the user.

3. How does the program solve an integral?

The program uses numerical methods, such as the trapezoidal rule or Simpson's rule, to approximate the value of the integral. These methods involve dividing the area under the curve into smaller, simpler shapes and then summing their areas to get an approximation of the integral.

4. Can the program solve any type of integral?

The program is designed to solve definite integrals with a given interval of integration. It can handle a wide range of functions, including polynomial, trigonometric, and exponential functions. However, it may not be able to solve more complex integrals that require advanced techniques or involve special functions.

5. How accurate are the results from the program?

The accuracy of the results depends on the chosen method and the number of intervals used in the calculation. Generally, the more intervals used, the more accurate the result will be. However, there may be some error due to the approximation method used.

Similar threads

Replies
16
Views
2K
Replies
2
Views
934
Replies
8
Views
180
Replies
3
Views
1K
Replies
2
Views
293
Replies
1
Views
850
  • Calculus
Replies
1
Views
993
Replies
16
Views
1K
Replies
2
Views
1K
Back
Top