# Thread: Integrals in computers

1. ## Integrals in computers

Hello everyone I would like to calculate the following integral using computer (because I have to calculate many of them , in different scenarios).

The integral is of the form

Integrate the
s(x)*g(x) from the interval of [a,b]

First I want to understand how to calculate the multiplication of two function before feeding them into the integral function

Regards
A

2. The two most common ways to evaluate integrals of products are "integration by parts" and "substitution".

I suggest you look them up.

3. Originally Posted by dervast
Hello everyone I would like to calculate the following integral using computer (because I have to calculate many of them , in different scenarios).

The integral is of the form

Integrate the
s(x)*g(x) from the interval of [a,b]

First I want to understand how to calculate the multiplication of two function before feeding them into the integral function

Regards
A
That is too vague please provide more context or explanation

CB

4. Hello,
I would like to thank you for your answers.
I tried to upload a pretty simplified version of what I want to calculate so to build understanding how integration works in computers.

ImageShack&#174; - Online Photo and Video Hosting

In the image you will see three plots: s(x), g1(x),g2(x)

At the bottom of the image are the two integrals that I would like to find:
s(x)*g1(x)
s(x)*g2(x).

So first I multiply the two functions and then I integrate them?

5. Originally Posted by dervast
Hello,
I would like to thank you for your answers.
I tried to upload a pretty simplified version of what I want to calculate so to build understanding how integration works in computers.

ImageShack&#174; - Online Photo and Video Hosting

In the image you will see three plots: s(x), g1(x),g2(x)

At the bottom of the image are the two integrals that I would like to find:
s(x)*g1(x)
s(x)*g2(x).

So first I multiply the two functions and then I integrate them?
That is still too vague, do you want to use numerical integration methods, do you want an analytic/exact result, ...

CB

6. Numerical integration

7. Then I can see no problem with the multiplication. You have values of f(x) and g(x) at various points- just multiply them together to get f(x)g(x). Yes, you "multiply then then integrate them". That is what " $\int f(x)g(x)dx$" means!

What integration algorithm are you using, Simpson's rule?

8. Originally Posted by HallsofIvy
Then I can see no problem with the multiplication. You have values of f(x) and g(x) at various points- just multiply them together to get f(x)g(x). Yes, you "multiply then then integrate them". That is what " $\int f(x)g(x)dx$" means!

What integration algorithm are you using, Simpson's rule?
There is a technical difficulty in that one of the functions is a saltus function (a step function), which means that most numerical integration schemes become inefficient. The best policy would be to decompose the integrals into a sum of integrals over the intervals on which the saltus function is a constant.

CB

9. Originally Posted by CaptainBlack
There is a technical difficulty in that one of the functions is a saltus function (a step function), which means that most numerical integration schemes become inefficient. The best policy would be to decompose the integrals into a sum of integrals over the intervals on which the saltus function is a constant.

CB
I would like to thank you for your reply all.
Actually for fun sake I tried numerical integration and if step function has only few steps (like 5-10) I get good results... but when the function has like 800steps then I get errors. thus I would like to ask you for a reference
--> that explain the difference between numerical,analytic/extact integration, and anything else that has to do with calculating integrals in computers.

I will also try the solution Captain Black suggested to decompose the integrals into a sum of integrals and I ll post back again.

Regards and Happy new Year!
Alex

EDIT: One more thing I noticed a step function is not continuous thus can not be integrated. Is that right?

10. Originally Posted by dervast

EDIT: One more thing I noticed a step function is not continuous thus can not be integrated. Is that right?
No a piecewise continuous function is integrable.

CB

11. I would like to thank you for your answer.
So to make sure I got it right
a. If you want to integrate a function has to be continuous.
b. If you want to integrate a step function (which is ofc. not continuous) you have to do find the integrals for the smallest step functions.

Do you agree with that?

I would like to thank you in advance for your help
Best Regards
Alex