Integration

This is a discussion on Integration within the A Brief History of Cprogramming.com forums, part of the Community Boards category; Which numerical integration method is best to use for an arbitary function of which nothing is known? Currently I'm using ...

  1. #1
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072

    Integration

    Which numerical integration method is best to use for an arbitary function of which nothing is known?

    Currently I'm using "Simpson's rule", something I found using google. I found something called the "Romberg method" too, but I was unable to find its implementation.

    "Simpson's rule" seems quite OK, though.

    Secondly, when you are writing math formulas using ascii, how do you write integrals?
    Examples:
    Code:
    integrate(f, a,b)
    integral{a,b}(f)
    §[a,b] f(x)
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  2. #2
    Senior Member joshdick's Avatar
    Join Date
    Nov 2002
    Location
    Phildelphia, PA
    Posts
    1,146
    Which numerical integration method is best to use for an arbitary function of which nothing is known? Currently I'm using "Simpson's rule", something I found using google."
    That's a good method. The other way I was taught in AP Calc was called the Trapezoidal Rule, but the Simpson's Rule has less of a margin of error; however, it is easier to calculate the margin of error for the Trapezoidal rule. It all depends on how precise you need to be. You could always increase the number of partitions to gain better accuracy.

    Secondly, when you are writing math formulas using ascii, how do you write integrals?
    Examples:
    Code:
    integrate(f, a,b)
    integral{a,b}(f)
    §[a,b] f(x)
    If you mean in your code, I'd suggest that first one; it's the only one that I think is valid code. If you're outputting the integral, the last one looks the best.
    FAQ

    "The computer programmer is a creator of universes for which he alone is responsible. Universes of virtually unlimited complexity can be created in the form of computer programs." -- Joseph Weizenbaum.

    "If you cannot grok the overall structure of a program while taking a shower, you are not ready to code it." -- Richard Pattis.

  3. #3
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    Originally posted by joshdick
    That's a good method. The other way I was taught in AP Calc was called the Trapezoidal Rule,
    Yes, I tested the trapezoidal rule and found that it gave much less precision with much more steps.
    Originally posted by joshdick
    If you mean in your code, I'd suggest that first one; it's the only one that I think is valid code.
    The thing is, I'm creating my own programming language (see my sig), and I want the syntax to be as intuitive as possible.
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  4. #4
    Senior Member joshdick's Avatar
    Join Date
    Nov 2002
    Location
    Phildelphia, PA
    Posts
    1,146
    Originally posted by Sang-drax
    The thing is, I'm creating my own programming language (see my sig), and I want the syntax to be as intuitive as possible.
    Wow, man, that's really ambitious. Very cool. I like a lot of your features. It's like you're taking all of the little annoying obstacles in C++ and getting rid of them. In your case, I think that third way looks the nicest. The only thing is, how do type that symbol? I don't think most programmers want to have to hit something like shift+option+ctrl, etc. It looks nice; I think that third way would be nice for output, but I think it'd be bothersome to program that symbol.

    Kudos for undertaking such a project. Oh, and what does your signature mean?
    FAQ

    "The computer programmer is a creator of universes for which he alone is responsible. Universes of virtually unlimited complexity can be created in the form of computer programs." -- Joseph Weizenbaum.

    "If you cannot grok the overall structure of a program while taking a shower, you are not ready to code it." -- Richard Pattis.

  5. #5
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    Yes, there's a problem with the '§' character -- it doesn't look the same in a console window and in a windows edit control.
    It is quite easy to type on my keyboard (swedish) though.

    And my signature?
    I found a quote in Latin saying "Quidquid Latine dictum sit, altum videtur", it means "Whatever is said in Latin sounds profound". I used that quote for a while, then I wanted to reduce my sig to one line only.
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  6. #6
    Senior Member joshdick's Avatar
    Join Date
    Nov 2002
    Location
    Phildelphia, PA
    Posts
    1,146
    Will your language support OOP?
    FAQ

    "The computer programmer is a creator of universes for which he alone is responsible. Universes of virtually unlimited complexity can be created in the form of computer programs." -- Joseph Weizenbaum.

    "If you cannot grok the overall structure of a program while taking a shower, you are not ready to code it." -- Richard Pattis.

  7. #7
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    That would indeed be nice.

    I have been experimenting a little with different syntaxes to implement objects. As I've said, I'd like the syntax to be as easy as possible.
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  8. #8
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,386
    >Secondly, when you are writing math formulas using ascii, how
    >do you write integrals?

    I've used the simulation program PSI a lot, it had an easy, nice and intuitive language.

    Integration had the following notation:

    y = int (f par: y0);

    When writing ASCII integrals in documents I prefer a notation like the one below. For the given integral above it would be:

    Code:
    
              o-o
               /
    y = y(0) + | f(x) dx
               /
             -o-o
    
    >The thing is, I'm creating my own programming language (see
    >my sig), and I want the syntax to be as intuitive as possible.

    Interesting, what kind of language? A general purpose language? Or mathematical language?
    Last edited by Shiro; 01-02-2003 at 08:31 AM.

  9. #9
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    Originally posted by Shiro

    Interesting, what kind of language? A general purpose language? Or mathematical language?
    Mainly a mathematical lanuage.
    It has built-in support for complex numbers, vectors, matrices, etc.

    It is inspired by C++, Pascal and a bit from the TI-83 and Casio calculator languages.
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  10. #10
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,386
    In that case you might want to take a look at Matlab. It has a language designed for numerical calculations. For some Matlab examples take a look at:

    http://www.cs.uaf.edu/~bueler/MatlabEx.htm

    It has some nice constructions for use with matrices and vectors, but it is not always a very intuitive language. The way of for-loops in Matlab is an example of it:

    for j = 1:2:n-1

    This is the same as:

    for (j = 1; j <= n-1; j += 2)

  11. #11
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    Originally posted by Shiro
    It has some nice constructions for use with matrices and vectors, but it is not always a very intuitive language. The way of for-loops in Matlab is an example of it:

    for j = 1:2:n-1

    Yes, I've looked at Matlab, although I'm using a program called Mathcad much more. It represents its formulas graphical.

    For-loops look like this in Omicron:
    Code:
    for i = 1 ... x+2
    //..
    next
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  12. #12
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,386
    MathCad, I've heard of it, but never used it. But I know it is like Maple, it also gives the graphical representation of formula's, just as you put them to the paper.

    The for-loop in Maple is a bit easier to understand, it is like:

    for i from 1 by 2 to 100 do print(i) od;

    You can also do such like this, combine for with while:

    for i from 1 by 2 while i < 100 do print(i) od;

    Using words instead of abstract operators is more typing, but in my opinion it is also more intuitive and easier.

    [edit]
    BTW, I've been in Växjö last year, but I still don't know how to pronounce it in Swedish? Could you write it phonetic?
    [/edit]
    Last edited by Shiro; 01-02-2003 at 09:21 AM.

  13. #13
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    Originally posted by Shiro

    [edit]
    BTW, I've been in Växjö last year, but I still don't know how to pronounce it in Swedish? Could you write it phonetic?
    [/edit]
    You have? Interesting...
    Are you from the Netherlands?
    I remember that my school (Katedralskolan) had an exchange with a school in the Netherlands.

    As for the pronounciation of "Växjö":
    • First sound is a normal 'v'-sound, as in 'vacation' or 'very'
    • seconly, the same sound as the first sound in 'extra'
    • then a normal 'k'
    • then a 'sch'-sound, like the german word 'scheisse'
    • the last sound is the same as in the german word for oil: 'öl'

    stress the first vowel
    Last edited by Sang-drax; 01-02-2003 at 04:45 PM.
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  14. #14
    Registered User sean345's Avatar
    Join Date
    Mar 2002
    Posts
    346
    Just to say something about integration:
    It depends on the function when choosing between Simpson's Rule, Trapezoidal rule, right, left, or middle methods.

    On average Simpson's rule is a better estimation. There are some functions though where others will be better. Simpon's Rule creates parabalas and then calculates the area under them. This is based on that any 3 points can be used to create a parabala.

    You can calculate the error percent based on the rule. I forgot the exact equations. You can probably find them on-line though. You need to find the point where the second and fourth derivitive diverges to, though. I'm not sure how you could do this in a programming language without a significant amount of calculations.

    - Sean
    If cities were built like software is built, the first woodpecker to come along would level civilization.
    Black Frog Studios

  15. #15
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    Originally posted by sean345

    You can calculate the error percent based on the rule. I forgot the exact equations. You can probably find them on-line though.
    Yeah, here's a good page (PDF)
    http://www.eeng.dcu.ie/~ee317/Course_Notes/Numintg.pdf
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 06-04-2009, 09:18 AM
  2. Numerical Integration by Trap Rule.
    By hexagons in forum C Programming
    Replies: 3
    Last Post: 03-25-2009, 10:12 AM
  3. Numerical Integration
    By Crazed in forum C Programming
    Replies: 13
    Last Post: 03-03-2008, 02:01 PM
  4. PC Cam Integration
    By neo_phyte in forum Networking/Device Communication
    Replies: 0
    Last Post: 10-25-2006, 01:34 AM
  5. perform numeric integration
    By Frank_Rye in forum C Programming
    Replies: 5
    Last Post: 10-18-2005, 01:17 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21