View Full Version : Maths in plain C++

fullmetalcoder

24th January 2006, 11:02

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... :o

Any things you would like to find in such an app?

Codepoet

24th January 2006, 12:13

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 :rolleyes:

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

wysota

24th January 2006, 13:57

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 (http://speedcrunch.digitalfanatics.org)?

Codepoet

24th January 2006, 14:17

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

wysota

24th January 2006, 14:18

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.

fullmetalcoder

25th January 2006, 09:19

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 :o )

thanks

Codepoet

25th January 2006, 13:42

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...

wysota

25th January 2006, 15:02

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?

Codepoet

25th January 2006, 15:17

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.

wysota

25th January 2006, 15:28

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.

Codepoet

25th January 2006, 15:49

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 :rolleyes:

fullmetalcoder

27th January 2006, 14:06

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

Actually I didn't! :D

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!!! :cool:

Powered by vBulletin® Version 4.2.5 Copyright © 2023 vBulletin Solutions Inc. All rights reserved.