You are not logged in.
I'm looking for a programming language that will allow me easily to manipulate complex numbers. Specifically, I need to be able to do things like multiply complex numbers and raise e to complex powers. The most important thing is that the code needs to be readable, so that it can be understood by someone with relatively little programming background. C (which is normally my preferred language) is not an option because complex numbers aren't part of the language and would have to be implemented with structures and helper functions. Maxima is a possibility, but I would prefer something with a more normal (C- or Java-like) syntax. Maple has a better syntax, but it's proprietary and expensive. Are there any other options out there?
Offline
If you like Python try NumPy/SciPy packages.
If you need a matlab-like language try octave, or for a comple mathematical software solution try Sage.
If you want to have C/Java style syntax then C++ could be a way to go, a complex number class with operator overloading is not a hard thing to write, but you can find plenty of it across the web.
edit: the C++ standard library has a complex number implementation.
Last edited by ijanos (2011-09-15 14:51:28)
Offline
The C++ implementation looks promising. Thanks!
Offline
D (v2) has a std.complex module and a syntax very close to C:
import std.complex, std.stdio;
void main() {
writeln( complex(1,1) ^^ complex(2,2) );
}This returns:
-0.265654+0.319818iIs that correct? ![]()
Edit: ^^ means power.
Edit 2: According to WolframAlpha, it is.
Last edited by stqn (2011-09-15 16:13:29)
Offline
Complex numbers are part of the C programming language in the latest standard, c99. Just #include complex.h and compile with -std=c99 (gcc).
Offline
Thanks for all the replies. I had no idea there were so many options out there! I'll probably take what C99 has to offer since I'm most familiar with that language already.
Offline
I work with complex numbers frequently, I personally prefer writing all of my simulations and calculations using GNU/octave. Some of the benefits include built in functions for operating on complex numbers, it's a language designed for mathematical calculation, and plotting data with gnuplot is easy as pie.
If you are looking for something a little more robust (as in trying to build a program with a gui interface or a bigger program that just happens to use complex numbers frequently) I'd probably suggest python as an alternative, as it is a full easy to use language with built in support for complex arithmetic.
Hofstadter's Law:
It always takes longer than you expect, even when you take into account Hofstadter's Law.
Offline
-0.265654+0.319818iIs that correct?
Yes.
To the OP, have you looked at Maxima? It is not a general purpose language, but it is scriptable, integrates with GNUPlot, has GUI front ends (wxMaxima), and exports equations and results nicely to LaTex.
Oh, and it handles complex numbers like a dream. It even makes Laplace transforms a breeze.
Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
The shortest way to ruin a country is to give power to demagogues.— Dionysius of Halicarnassus
---
How to Ask Questions the Smart Way
Offline
To the OP, have you looked at Maxima? It is not a general purpose language, but it is scriptable, integrates with GNUPlot, has GUI front ends (wxMaxima), and exports equations and results nicely to LaTex.
Oh, and it handles complex numbers like a dream. It even makes Laplace transforms a breeze.
I use Maxima often. As I said in my original post, I wanted something with a more C-like syntax. Since "rockin turtle" has pointed out that C does in fact have support for complex numbers, I've taken that route.
P. S. The project (which is done now) was to implement an FFT, first of all to test my own knowledge of the algorithm and possibly to give a presentation on later -- maybe I should have mentioned this earlier.
Offline
I'm not sure about what you want to do with complex numbers, but have a look at the calc package. It handles complex numbers natively and it's programmable (looks like C (one of the most beautiful language in the world IMHO
) ).
Last edited by xamaco (2011-09-17 11:06:50)
Offline
I am slightly surprised that no one mentioned Lisp.
It's the perfect language for mathematics. ![]()
It's written #c(r i), where r is the real part and i is the imaginary part.
Of course, Lisp might not be your cup of tea, but it's the most mathematical language I know of.
Last edited by jacmoe (2011-09-18 19:18:32)
Less noise. More signal.
Offline
...The project (which is done now) was to implement an FFT, first of all to test my own knowledge of the algorithm and possibly to give a presentation on later -- maybe I should have mentioned this earlier.
Although this is moving off topic, If you really want to understand the FFT, have you looked at how it is implemented in a DSP? Configuring hardware address generators to generate the butterfly sequences is what really drove it home for me.
Here is a link to a low cost development system: http://www.ti.com/tool/tmdx5535ezdsp
It might make for an interesting presentation
Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
The shortest way to ruin a country is to give power to demagogues.— Dionysius of Halicarnassus
---
How to Ask Questions the Smart Way
Offline
I think that's a little beyond me at this point, ewaller, but thanks. ![]()
Offline
I am slightly surprised that no one mentioned Lisp.
It's the perfect language for mathematics.
It's written #c(r i), where r is the real part and i is the imaginary part.
Of course, Lisp might not be your cup of tea, but it's the most mathematical language I know of.
I'm surprised nobody suggested Haskell. It's practically executable math.
In Zen they say: If something is boring after two minutes, try it for four. If still boring, try it for eight, sixteen, thirty-two, and so on. Eventually one discovers that it's not boring at all but very interesting.
~ John Cage
Offline
There's always fortran if you need performance. Fortran has builtin type Complex. If you want arbitrary precision there are a few packages available for fortran90 or later.
Python has some good features and is highly recommended if you don't need high precision with speed.
Offline
There's always fortran if you need performance. Fortran has builtin type Complex. If you want arbitrary precision there are a few packages available for fortran90 or later.
Python has some good features and is highly recommended if you don't need high precision with speed.
Since I know NumPy/SciPy and are very fast since they were written using C and Fortran.
Offline