It looks like you're new here. If you want to get involved, click one of these buttons!

This forum is in permanent archive mode. Our new active community can be found here.

I've been wanting to learn how to program for a while now and have decided to learn C++. I have decided that the project I want to work on is a dynamical systems simulator. I would like to know (1) What C++ compiler the forum recommends, and (2) What algorithm you would suggest for simulating second order systems.

Love,

Asnabel

## Comments

How to Think Like a Computer Scientist. Forget about making anything complicated your first time as it will only lead to frustration and you'll give up on your project.EDIT:So what exactly does using Python require?

I've been wanting to learn cabinetmaking for a while now and have decided to learn how to use a hammer. I have decided that the project I want to work on is a 6-drawer dresser. I would like to know what hammer the forum recommends and what nails you would suggest.Your first problem is that you are deciding before you learn. You are saying you don't know how to program, but apparently you feel like you know enough to be making all sorts of decisions. Think about that for a second. You admit you know nothing, but you are making decisions. Not much more needs to be said on that.

Let me put you on the right track.

First, is your primary goal to learn programming, or is it to solve your math problem? If your primary goal is to learn programming, you need to learn the fundamentals first. You can't just wake up one day and start doing calculus. You need to start in Kindergarten with addition and subtraction.

If your primary goal is to solve the problem, then you only really need to ride on the backs of programmers who came before you to get to the finish line as quickly and easily as possible. You can go around the Internet and find existing code you can just reuse and recombine into what you need. scipy and bioperl are great examples of libraries that scientists can use to do useful things without being excellent at programming.

Lastly, your request for an algorithm is quite silly. A program is an algorithm. Programming is the act of writing new algorithms. If an algorithm already exists, then that means the software you want already exists. If the software you want does not exist already, then you have to figure out the algorithm. That's what programming is.

I do always suggest that people have a project in mind if they want to start programming, but choosing something that is incredibly advanced as your first program is a sure way to fail. There's a big gap between hello world and advanced simulation you need to cross.

Also, existence of an algorithm does not imply existence of an implementation of that algorithm, I can think of at least a dozen different list sorting algorithms, none of which exists as computer programs (very few apart from these do).

Regardless of these semantics, it is still silly to ask for an algorithm if you don't specify the problem beyond "second order dynamical problem".

Also, which sorting algorithms do not exist in software? Is it because they are inefficient and useless, or it is because implementation with only binary logic is not possible?

Also, I have a feeling that existing libraries like numpy and scipy already have much of the math already implemented.

For example, I would say that the set of instructions to get out of a hedge maze from a specific point, is not an algorithm. The set of sets of instructions to get out of a hedge maze from any point in the maze is not an algorithm. The instruction set "Walk forwards, At dead ends turn around, At crossings always turn right" is an algorithm for getting out of any hedge maze, from any point within he hedge maze. I was talking about the former case (I'm quite sure the latter would win me some sort of prize), e.g., quicksort but after each switch there is a step to google my name and before each pivot selection roll 2d20. This is an algorithm (by the most general definition at least), but I am very certain that it does not exist as a computer program anywhere (at least until you decide to code it ^_- ).

There are two problems you're going to run into:

1) If there are a lot of particles (n) in your system, the calculation of the potential will take O(n^2) time.

2) If the distance particles travel in one time step becomes large compared to the distances between particles and / or compared to the distance over which the potential changes significantly.

Solving these two problems algorithmically is a much harder task, especially if you want to do it optimally. If you only model two blobs moving around each other you will not encounter problem 1) and you can solve problem 2) by making the time slice proportional to the distance between the bodies.

EDIT: if you get this done, you have to post a video (or didn't happen ;-) ).

For any numerical problem, if performance isn't such an issue then high-level language features and stuff like full mathematical vector/matrix manipulation are invaluable. MATLAB, Octave, and Python with Numpy and Scipy are extremely good tools for this kind of thing, and since you also want to learn something of programming in the process, Python is a clear winner. True, but implementing a well-known algorithm from a mathematical or English description is very helpful in learning to program. I believe that what Asnabel is asking for is some mathematical background and a hint as to the category of algorithm to use, so he can implement it himself. What you have is a system of ordinary differential equations. Presumably, if you want a simulation, you will input a set of initial conditions and let it run. This is called an Initial Value Problem (IVP). You will probably want to use an explicit Runge-Kutta method.

You will probably learn the most if you stick with something like Euler's method. Is that enough, Asnabel?

As far as getting a solution to the problem is concerned, Scott is correct - SciPy includes ode solvers. Obviously, you would still need to work out how to translate your problem into something SciPy will be able to use. However, in order to do that it would be best if you actually understand what an ode solver is doing behind the scenes.

The problem with RK is that it takes more calculations per time step, so regulating the size of the step becomes more important. However, since the method is more complex, it is much harder to optimize the step size. Overall, you may be better off using a simpler method where the step size is easier to optimize.

All in all it depends on the details of your simulation, but if this is a "for fun" project, using RK is overkill.

EDIT: and the solution to using RK in your scenario is to do it first for the velocity (vx,vy) from the potential/acceleration (this is a first order problem) and then the coordinates (x,y) from the velocity (again a first order problem).

*applies nose to grindstone*

EDIT: Also, should I use Python 2.6.4 or 3.1.1?