| New Reply |
Which programming language should I use? |
Share Thread | Thread Tools |
| Oct5-11, 12:58 PM | #1 |
|
|
Which programming language should I use?
I was wondering which programming language I should learn for general purpose calculations and physics simulations.
I already know a bit java. |
| Oct5-11, 02:37 PM | #2 |
|
|
I suppose it would depend upon what compilers were available on the computer you intend to use. Fortran is the old standby, but there are others out there that are probably just as effective.
|
| Oct5-11, 03:04 PM | #3 |
|
|
That seems to be a bit of a theological question around here (and probably everywhere). Different folks will SWEAR to you that only <insert preferred language name> is the right one. Java will do you fine, as will others. FORTRAN, as old and creaky as it is, has TONS of subroutines that have accumulate over the years specifically for scientific applications so that's in its favor. If you plan on doing much in modern computing, especially outside of science programming, I recommend that whatever you pick, it be fully OO like Java or C++ or C# or VB.NET
|
| Oct6-11, 02:24 AM | #4 |
|
|
Which programming language should I use?You might even have to learn vector based CPU instructions, if speed is super super critical. An example of SIMD instructions are the SSE and SSE2 instruction sets for common x86-type platforms. |
| Oct6-11, 02:34 AM | #5 |
|
|
Fortran 77. Is there another language yet that directly handles complex variables?
For 'general' use (implying graphs, diagrams and 'free') I was planning to take a good look at the current state of VPython sometime. Has anyone any experience with VPython? |
| Oct6-11, 06:26 AM | #6 |
|
|
But if I were you, I'd just stick with Java if you already know it well. I know that the big particle-in-cell codes are mostly written in C++ or Fortran, but Java is starting to show up more and more, and they all have comparable speeds. These days it doesn't matter as much. It really comes down to using what you're most comfortable with. |
| Oct6-11, 06:36 AM | #7 |
|
|
I would hazard a guess however that if it is indeed fully OO it really doesn't much resemble the original FORTRAN at all so I pretty clearly need to just stop thinking of it as FORTRAN at all |
| Oct6-11, 06:44 AM | #8 |
|
Mentor
|
Code:
#include <iostream>
#include <complex>
using namespace std;
int main ()
{
complex<double> z1, z2, z3;
z1 = complex<double> (1.0, 2.0);
z2 = complex<double> (3.0, 4.0);
cout << "z1 = " << z1 << endl;
cout << "z2 = " << z2 << endl;
z3 = z1 + z2;
cout << "Sum = " << z3 << endl;
z3 = z1 * z2;
cout << "Product = " << z3 << endl;
return 0;
}
|
| Oct6-11, 07:46 AM | #9 |
|
|
OK, so what does C++ return when you enter cos-¹(2)?
F77 returns a complex value. |
| Oct6-11, 07:58 AM | #10 |
|
Mentor
|
No go... the C++ standard library doesn't seem to include a version of acos() for complex numbers. It does include automatically-overloaded complex versions of cos(), cosh(), exp(), log(), log10(), pow(), sin(), sinh(), sqrt(), tan(), tanh(). (I tried cos().)
However, you can write your own complex inverse trig functions using the complex logarithmic forms: http://en.wikipedia.org/wiki/Inverse...arithmic_forms Code:
#include <iostream>
#include <complex>
#include <cmath>
using namespace std;
// my attempt at a complex-valued acos() function
complex<double> acos (const complex<double>& x)
{
const complex<double> eye = complex<double>(0,1);
const complex<double> one = 1;
return -eye*log(x + eye*sqrt(one - x*x));
}
int main ()
{
complex<double> z = 2;
cout << acos(z) << endl; // this outputs "(0,1.31696)"
return 0;
}
|
| Oct6-11, 08:41 AM | #11 |
|
Recognitions:
|
I'd hope that a commercial compiler like ifort can handle double precision complex properly, but I've never had the opportunity to test it. I've got to admit Fortran 90 (and onward) has come a long way, and it's probable still a contender for number crunching programs. I'm not really fan of Fortran as a general purpose language though. It still carries some legacy stuff that I hate. I don't like implicit typing (or having to "implicit none" for every function) and I really hate Fortran I/O. |
| Oct6-11, 08:49 AM | #12 |
|
|
If you want (/need) flash and bling, buy MatLab. |
| Oct6-11, 10:40 AM | #13 |
|
Recognitions:
|
Actually that is a bit of a plus for Fortran, it's close syntax similarity to matlab is very handy. |
| Oct6-11, 11:02 AM | #14 |
|
Recognitions:
|
I'm surprised that they didn't include inverse trig's in the c++ complex implementation, as jtbell pointed out above it's not very difficult. I just wrote the following inverse trig library in about 15 minutes if anyone wants it. I even threw in the hyp-trig's at no extra cost. ![]() Code:
/* File complex_itrig.h */
/* Uart's complex inverse trig library */
#include <complex>
typedef std::complex<double> cmplx;
const cmplx _I = cmplx(0.0,1.0);
const cmplx _1 = cmplx(1.0,0.0);
cmplx atan(cmplx x) {
return 0.5*_I*( log(_1 - _I*x) - log(_1 + _I*x) );
}
cmplx asin(cmplx x) {
return atan( x / sqrt(_1-x*x) );
}
cmplx acos(cmplx x) {
return atan( sqrt(_1-x*x) / x );
}
cmplx acosh(cmplx x) {
return -_I * acos(x);
}
cmplx asinh(cmplx x) {
return -_I * asin(_I*x);
}
cmplx atanh(cmplx x) {
return -_I * atan(_I*x);
}
|
| Oct6-11, 02:24 PM | #15 |
|
|
and quickly getting it somewhat working, I use VPython. |
| Dec15-11, 05:18 AM | #16 |
|
|
Hi...i'm new to ths blog.....
Plz tel me, hw s Fortran(Gfortran95) language? |
| Dec15-11, 05:28 AM | #17 |
|
Recognitions:
|
I'll advocate Python (good enough for general purpose, and fairly simple to learn) and its scientific libraries (for physics simulations, as you mentioned, although this term is a bit broad but you can definitely do a lot with Python).
|
| New Reply |
| Tags |
| java, language, programming, simulations |
| Thread Tools | |
Similar Threads for: Which programming language should I use?
|
||||
| Thread | Forum | Replies | ||
| Which programming language is best? | Academic Guidance | 12 | ||
| Recommended programming language (and texts) for middle-school beginner programming | Programming & Comp Sci | 9 | ||
| Programming language | Programming & Comp Sci | 10 | ||
| Which programming language do you use? | Academic Guidance | 20 | ||
| Which programming language is the best ? | Programming & Comp Sci | 15 | ||