Thread: Integration with C++

  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    224

    Cool Integration with C++

    Hi guys,

    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.Integration with C++-temp-jpg

  2. #2
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472
    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:

    Code:
    for loop until finished
    {
        somedatatype answer = 0;
        answer = DoMaths(args...);
    }
    
    DoMaths(args...)
    {
        somedatatype ans = args used in mathematical expression here
        return ans
    }
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

  3. #3
    Registered User
    Join Date
    Nov 2006
    Posts
    224
    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.

    cheers

  4. #4
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472
    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
    Last edited by rogster001; 10-05-2011 at 05:12 AM.
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

  5. #5
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    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.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  6. #6
    Registered User
    Join Date
    Nov 2006
    Posts
    224
    Hi grumpy,

    Thanks.


    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.

    cheers

  7. #7
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,949
    Look up what grumpy said, that is your answer. There are no built in functions for calculating integrals in the C++ language.
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

  8. #8
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    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.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  9. #9
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Quote Originally Posted by Elysia View Post
    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.
    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.

    Getting convergence when numerically computing an integral is more difficult when the function is "peaky".

    Quote Originally Posted by Elysia View Post
    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.
    The integral is obtained by multiplying the sum by h in this case.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  10. #10
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    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.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Integration with Web?
    By dluthcke in forum C++ Programming
    Replies: 25
    Last Post: 09-30-2009, 12:02 AM
  2. PC Cam Integration
    By neo_phyte in forum Networking/Device Communication
    Replies: 0
    Last Post: 10-25-2006, 01:34 AM
  3. Integration Problem
    By Tarento in forum C Programming
    Replies: 5
    Last Post: 05-09-2006, 12:48 AM
  4. Integration
    By westclok in forum C Programming
    Replies: 8
    Last Post: 02-01-2005, 05:06 AM
  5. Integration
    By Sang-drax in forum A Brief History of Cprogramming.com
    Replies: 17
    Last Post: 01-03-2003, 04:08 AM