Archive for the 'Programming' Category

June
27th 2008
CPU speed and FLOPS

Posted under Computer & Programming

You might have read my post, Prime numbers and Ruby, and wondered why the program used a huge amount of time, and even after 25 hours of computing, the program did not have an answer. The code of the program is really not that advanced, but when the input number is a big prime number, the number of calculations needed is huge.

I do want to run the program again, with the same number. I have also tried to make a similar program in C++, but unfortunately, that version of the program won’t even accept the input number to be that big. Anyway, I thought if I should run it again, I might want to do some thinking and try to figure out how much time my computer will use, and then I need the amount of FLOPS the computer is capable of. My CPU is a Intel Celeron at 1.60 GHz. I have tried to figure out how many FLOPS I can expect, but I haven’t found out anything clever. If anyone know how to calculate this, I would be grateful.

Anyway, with the number I typed in, I have found out that I need roughly 68 630 000 000 000 (could be wrong) floating point operations to be able to say that the number I wanted to check is a prime number. The CPUs in the PlayStation 3 runs at 218 GFLOPS (218 000 000 000 FLOPS), which would mean that the PS3 would need approximately 315 seconds, which is 5 minutes and 15 seconds. That’s right. And that is for the PS3, which is much faster than my computer! The PS3 is actually so powerful that the University of Bergen have bought five of them to use them in education and to to heavy calculations. They connected the five PS3s together, to make use of the power and have one machine capable of one teraFLOPS. Their last supercomputer was capable of 0.7 teraFLOPS.

Basically, I have found out that my computer will use an awful lot of time to finish the calculations, but I will do it. I’m actually pretty excited to find out how much time is needed.

4 Comments »

June
25th 2008
A program that solves quadratic equations (C++)

Posted under C++ & Programming

I’m still a beginner at programming. I have not really decided if I want to learn ruby or c++, but for now I think c++ is more versatile. Anyway, I have made a little program that solves quadratic equations, with both real and complex solutions.

The quadratic formula itself can be found in my post Solve quadratic equations with php. The difference between the solving in these two cases, is that the php-solver do not solve the equation if the solution is complex.

Until I figure out a smart way to display nice looking code in my posts, the code can be found here. If you are familiar with c++, you should understand quite easy. I don’t think it is to difficult if you are familiar with another programming language, or programming in general either.

Download the program. Don’t worry about it being and .exe-file, even though they potentially are dangerous. This one is perfectly safe to download and use. Show care when downloading from the Internet.

I use Code Blocks when programming in c++, both for editing and compiling.

4 Comments »

June
19th 2008
Prime numbers and Ruby

Posted under Programming & Ruby

I have recently started to learn how to program with Ruby. I am somewhat familiar with programming already, but by noe means an expert. I really do want to learn programming, so I started off with Ruby. One of my first programs is a program that checks if a number is a prime number. I have made the program in MATLAB earlier, so I just ported it, if one can say that.

Prime number program

Here you see the program in action. My computer have spent the last few hours trying to figure out if it is a prime or not. Yes, I know it is a prime, and therefore the program needs to do a lot more computing. After all, this is actually a quite big number. Even though it is a small program, with just 25 lines of code or so, it uses over 95 % of my CPU. Because of that, my computer is running a bit slow at the moment. Anyway, I will let the computer finish the calculations. I do wonder how much time it will need though.

I will keep you updated, and write a new post when the program gives me the answer. I will give you the code to, if anyone should be interested.

Update: The program have spent the last 22 hours trying to figure out if the number is a prime or not. I’m really beginning to wonder how much time is needed.

Update II: After about 25 hours, I logged in at my computer, and guess what? For some reason, the computer had decided to reboot. Not too happy about that. I actually suspect that the computer got overheated. Anyway, I will try again, but I might try on another computer. After all, the program uses a lot of resources, so I can’t really use the computer while running the program.

1 Comment »

June
18th 2008
Solve quadratic equations with php

Posted under PHP & Programming

Ever wanted to solve quadratic equations with php? When I started to learn php, I wanted to see if I could make a script that solved quadratic equations. In a course I participated in, we made a MATLAB-script that did just that. A quadratic equation is on the form aX2+bX+c=0, and the solutions can be found with the quadratic formula:
Quadratic formula to solve quadratic equations
Continue Reading »

No Comments »