Integration with C++
I need to integrate the attached equation in C++ 100's of times for various points on a grid (m,n).
I was wondering if there was a free to use and easy to use function somewhere that will allow me to integrate this function?
Any advice or help is much appreciated.Attachment 10966
You mean you need to translate this function into expressions that a program can read? Or you know how to do that but do not know how to place it in an algorithm that can be implemented with C++?
If its the first god knows, i can partially decipher it but if there was one thing i wish i had a guide to, or a truly concise glossary of it would be the grammar of this notation.
As for the second then its as easy as pseudocode:
for loop until finished
somedatatype answer = 0;
answer = DoMaths(args...);
somedatatype ans = args used in mathematical expression here
Hi thanks Rogster.
I'd say the answer is yes to both of those questions at the moment... lol. I'm scouting around for info but to no avail as yet.
Well the thing is, if you understand what the expression breaks down as in terms of mathematical operations then it's just a case of writing it out like that instead of the algebraic notation, and then converting the mathematical operators into the ones used in C++
like, using () can force priority of evaluation, same as elsewhere, * is multiply, / divide ...etc look em up there are tables out there for reference. What does it do anyway? is it something on lighting or graphics? - wild guess there from quick look at some of the bits
Firstly, you might want to google "abramowitz stegun" and see if you can find their famous handbook of mathematical functions. It does pay to look through such texts and see if you can find an analytical formula for doing your integration (which will probably be both less computationally demanding and more accurate than a numerical method).
If you can't find a way to integrate the function analytically, then google for "numerical integration". There is a bunch of methods you can use, all with various trade-offs.
In your formula, it might pay to be precise as to whether i is an index or the square root of -1.
i is a complex number.
I am no maths expert so I was hoping that others with experience could possibly help and that they might know of an easy way to do this.
Look up what grumpy said, that is your answer. There are no built in functions for calculating integrals in the C++ language.
Calculating an integral is rather trivial (especially if it's finite). Remember the definition of an integral: sum the value of f(x) in the internal [a, b]. That basically means you should calculate f(x) for every point, x, in [a, b]. The smaller the steps, the better.
So, say the interval I = [0, 1]. Then you sum f(0), f(0 + h) ... to f(1) where h is some small number. The smaller, the better accuracy, but the longer the calculation.
You can always choose some high value h, say, 0.1, then make it smaller until you see the calculated value converge to some number A. That is, the number A won't significantly change if you take smaller h.
The integral is not equal to the sum of values. It is necessary to normalise the sum using the distance between two adjacent points you compute f(x) for, in order to add up.
Originally Posted by Elysia
Getting convergence when numerically computing an integral is more difficult when the function is "peaky".
The integral is obtained by multiplying the sum by h in this case.
Originally Posted by Elysia
An integral is a sum of the function evaluated at different points, but that's not the completely picture. It's the basic picture, though. Damn, I've been forgetting things.