Results 1 to 12 of 12

Thread: Maths in plain C++

  1. #1
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Maths in plain C++

    hi,

    Months ago, I started to write a math app using GTK+, I finally changed my mind and ported it to Qt4.

    But the point is not in the GUI part which works flawlessly but in the core: I have already a few interesting things but it's not enough, I think.

    Here is what I implemented :
    - solvation of linear equations' systems using GAUSS method
    - prime number checking

    Graphing equation is planned but I'm really busy...

    Any things you would like to find in such an app?
    Current Qt projects : QCodeEdit, RotiDeCode

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    85
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Maths in plain C++

    Do you want to write a calculator or a computer algebra system?
    calculator:
    standard functions, graphing, numerical differentiation and integration of simple functions (polynoms, exp, sin(h), cos(h), tan(h), and inverse functions)
    Really cool are those RPN calculators because you don't need parentheses.
    Arbitrary precission

    computer algebra system: something like maple
    Hmm, I use mainly the following:
    calculus:
    symbolic differentiation and integration in arbitrary coordinate systems
    simplify
    numeric and symbolic root finding (with complex numbers)
    solving (ordinary) differential equations

    linear algebra: gauss , inverse, determinant, jordan normal form and other eigenvalue problems

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Maths in plain C++

    Quote Originally Posted by Codepoet
    calculator:
    standard functions, graphing, numerical differentiation and integration of simple functions (polynoms, exp, sin(h), cos(h), tan(h), and inverse functions)
    Really cool are those RPN calculators because you don't need parentheses.
    Arbitrary precission
    Have you seen SpeedCrunch?

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    85
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Maths in plain C++

    I'm even using it But I'm missing the RPN feature of my HP calculator...

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Maths in plain C++

    Quote Originally Posted by Codepoet
    I'm even using it But I'm missing the RPN feature of my HP calculator...
    RPN is one of the features on its todo list.

  6. #6
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Maths in plain C++

    could you give me some code snippets ??? I don't understand most of the maths you talked about, after all I'm only in High School (16 years old )

    thanks
    Current Qt projects : QCodeEdit, RotiDeCode

  7. #7
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    85
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Maths in plain C++

    So you want to program a calculator not a computer algebra system
    I don't have any code to do most of the things I talked about - I'm only using Maple and other math programs if I'm not doing it by hand. But I could show you the math behind it - that's "code" too

    I'll give you an example: You should know functions like f(x)=5 * x^2 + 4
    Now the derivative at a certain point, like x0 = 4, is the slope of the tangent at the graph of f at (x0, f(x0)). You could say: a point has no slope - how, it's just a point. So let's not start with a tangent but a secant ("Sekante" in German).
    That's a line with at least two intersections with the graph of f. Let's use (3, f(3)) and (5, f(5)). Now you can calculate the slope of the secant. Just delta y devided by delta x: (f(5)-f(3)) / ( 5 - 3). That's a very bad approximation. Now decrease the width of the interval, let's say to 0.1. You can do that with a calculator. And get ever more narrow. When you watch the secant while you are doing this you'll see that the two intersections will move together and if you continue forever the two points will be the same - you have no more a secant but a tangent at the graph. But you still know the slope of the "last" secant which is the slope of your tangent.
    In mathematical terms it's just (this is not a correct definition)
    limit of (f(x) - f(x0)) / ( x-x0) for x converging to x0 for any point x0
    Here the derivative would be f ' (x) = 10 * x
    (maybe some words are wrong due to my English...)
    http://en.wikipedia.org/wiki/Derivative has some nice pictures of this.


    Did you learn gauss's method in school??? That early??? I can't believe it...

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Maths in plain C++

    Quote Originally Posted by Codepoet
    Did you learn gauss's method in school??? That early??? I can't believe it...
    Isn't it the simplest way to solve algorithmically a set of linear equations?

  9. #9
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    85
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Maths in plain C++

    Sure - it is. I'm just wondering because I learned that algorithm "officially" the first time at university - not at school. At school we used another technique where you modified the equations to insert them into each other or added / subtracted them to eleminate variables.

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Maths in plain C++

    Quote Originally Posted by Codepoet
    Sure - it is. I'm just wondering because I learned that algorithm "officially" the first time at university - not at school. At school we used another technique where you modified the equations to insert them into each other or added / subtracted them to eleminate variables.
    Well... gauss does practicaly the same, just with matrices, doesn't it? Sure it is more advanced in details than pen & paper method but the concept is the same. At least that's what it seems to me -- I'm not an expert on this.

  11. #11
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    85
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Maths in plain C++

    Yes, the underlying operations are the same if you don't insert one equation into another. But that's only another way of adding / subtracting with a multiplication.
    Maybe I just had the wrong math teachers at school

  12. #12
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Maths in plain C++

    Quote Originally Posted by Codepoet
    Did you learn gauss's method in school??? That early??? I can't believe it...
    Actually I didn't!

    My sister, which is at an economic university, left a math book on her desk, the method was described inside and as it's the simplest way to do such a thing, and also the most easily translatable in C(++) code I chose it!!!
    Current Qt projects : QCodeEdit, RotiDeCode

Similar Threads

  1. QTextEdit + paste rich text as plain text only
    By Yong in forum Qt Programming
    Replies: 2
    Last Post: 6th February 2008, 16:45
  2. [QSettings] Why limiting to plain file or registry ?
    By lauranger in forum Qt Programming
    Replies: 8
    Last Post: 13th September 2006, 14:25
  3. QTextEdit API questions (plain text)
    By Gaspar in forum Qt Programming
    Replies: 4
    Last Post: 16th May 2006, 06:03

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.