dimitris kalamaras

math, social network analysis, web dev, free software…

Month: August 2008

Prime numbers’ generator

This is a Prime Numbers’ Generator from Integers up to 2,000,000,000, written in Turbo Pascal.
This program generates the prime numbers up to a given arithmetic limit, using 4 (four) different known methods. They are all based in modulo algebra. The methods are:

  1. This uses the mathematical definition of a prime number to generate them. A prime is only divided by 1 and himself. Disadvantage: The method is very slow.
  2. In this method, each number N is modulo divided only with the half of the numbers below it (N/2). Thus, the search is becoming faster than the first method.
  3. In the third method, a number, let N, is modulo divided only with the numbers up to sqrt{N}. As a result of that, the generation process is 10 times faster than the previous methods.
  4. The fourth method is the best of all. It is based on the 3rd method, only it bypass the sqrt{x} praxis, by modulo dividing each number N with the first, the second and the third prime number and then, if there is a residue, it modulo divides N with j, where j is an integer from j*j cdots N with step 2. The above trick has the eye-blink effect: the method generates primes (within a reasonable range) before you blink your eyes….:-)

Read More

Qt (Μέρος Ι): Convertor

Το Q Toolkit (Qt) είναι μία εργαλειοθήκη για δημιουργία εφαρμογών με γραφικό περιβάλλον (GUI), αντίστοιχη της GTK του Gnome. Ξεκίνησε να αναπτύσσεται το 1991 από τους Haavard Nord and Eirik Chambe-Eng και έγινε η βάση πάνω στην οποία στηρίχτηκε ολόκληρο το γραφικό περιβάλλον KDE. Ουσιαστικά, οι εκδόσεις του KDE ακολουθούν πάντα τις αναβαθμίσεις της Qt. H Qt αναπτύσσεται πλέον από τη Νορβηγική Trolltech, και υπάρχουν ανοικτού κώδικα εκδόσεις της για Unix, Mac OS, Windows και embedded συστήματα.

Λίγη ιστορία

Μέχρι την έκδοση 1.45, η άδεια χρήσης της Qt (FreeQt) δεν ήταν συμβατή με τις άδειες χρήσης ανοικτού κώδικα του OSI (www.opensource.org) αλλά και τον ορισμό του ελεύθερου λογισμικού (www.fsf.org), πράγμα που έκανε πολλούς developers να ανησυχούν για την εξέλιξη του KDE. Η άδεια άλλαξε με την Qt2 που είχε άδεια Q Public License, την οποία όμως το FSF θεώρησε και πάλι ασύμβατη με την GPL. Το αποτέλεσμα ήταν η ανάπτυξη ανταγωνιστικών προσπαθειών, όπως της εργαλειοθήκης Harmony και του Gnome. Το Harmony ήταν μια άδοξη προσπάθεια αναδημιουργίας της Qt με άδεια GPL ενώ, πιο φιλόδοξα, το Gnome έθεσε ως στόχο την αντικατάσταση του KDE στα desktops μας (από εκεί πηγάζει η αντιπαράθεση KDE εναντίον Gnome, που όμως έχει πλέον ατονήσει).

Read More

Sombrero!

The first blog post is usually some general introduction about the writer. I don’t like those posts so I start by testing my MathML installation.

To test it, let me try to write the “sombrero” function:

z={sin(sqrt(x^2 + y^2))} / sqrt (x^2 + y^2)

which is automagically constructed by Ron Fredericks‘ WP Math Publisher plugin using this line of code:

[pmath size=12]z=sin (sqrt (x^2 + y^2)) / (sqrt (x^2 + y^2))[ /pmath]

Integral in C (1997)

This program uses the basis of the Archimedes (287-212 BC) method, known as exhaustion, to approximate the integral of a given real function in a given space [a,b]. First it segments the given space into N subspaces. It calculates: a) the sum of the areas of orthogonal parallelograms of height equal to the minimum of the function in each segment and b) the sum of the areas of orthog. parallelograms of height equal to the max value of f(x) in each segment. Theoretically, when N right infty, the progressions are both converging to the same limit which is the integral of the function.

The program is simple. It requires the segmentation number N and the integration limits a,b. You can easily change the function to your desired one in the function at the end of the code. As you may see, after the calculations, it tries to graph the function. Well don’t expect much, although it has very good output in some functions like the f(x)=xsinx.

The program was written in Borland C++ 5.0. You will need the compiler bcc in order to compile and run it, but it’s very easy to make some alterations for other compilers or other OS’s.

Read More

Page 2 of 2

Powered by WordPress & Theme by Anders Norén