Why is C Preferred for Numerical Analysis over Fortran?

  • Fortran
  • Thread starter geouke
  • Start date
  • Tags
    Fortran
In summary: It can be argued that C++ is a more versatile language than Fortran, but the reality is that each language has its own strengths and weaknesses. Ultimately, the language you use to write your programs is going to be dictated by the type of programs you write and the problems you are trying to solve.
  • #1
geouke
9
0
I am a graduate geology student and have been using MATLAB for about a year now. I began learning C a while back to have a broader tool-set to work with but found that it just got in the way of learning material more specific to my major. Besides, MATLAB does everything I need anyway.

That being said, I do appreciate that free compilers are available for languages like C and Fortran and that they can execute models more quickly. I began to read an introductory text on Fortran the other day and it seems to be easier to learn than C. Perhaps like MATLAB, it is designed more for numerical analysis than general applications.

My question is this: is there really any advantage for someone like me to learn C instead of Fortran? I do not plan to write programs for a living, the standard tool-set used by the USGS to model groundwater flow (MODFLOW) is already written mostly in Fortran, and C seems to have a steeper learning curve and does not seem to execute programs any more quickly.

I am probably opening an old can of worms. I guess I am wondering why someone who works primarily with numerical analysis or modeling (in an academic sense rather than industrial) and does not plan to market themselves as a programmer upon graduation should learn C rather than Fortran. Cool tricks aside, why should C be the standard for serious numerical work rather than Fortran?

Thanks!
 
Technology news on Phys.org
  • #2
C as a language is more standardized than Fortran and has more uses as a programming language. True Fortran was designed to do numerical computations well. The variations in either language you might see are in libraries on various platforms or how C would interact with a given OS (windows vs unix/linux/macosx...).

The reality is you learn the language you need to use. If the problem you're working on references other peoples work and they used Fortran then you should use Fortran. If you're thinking of making your work available on many platforms then you might consider C/C++. If you plan to market your work on Android or make it available everywhere then you might consider Java.

With respect to Java, the Open Source Physics project has a large collection of simulations all done in Java using the the OSP library of ODE solvers, and display components that while not the fastest is more flexible than Matlab especially if you're sharing your work with others who may not have Matlab.

My language preference right now is Scala, touted as a better Java than Java with Object Oriented and functional programming capabilities merged together interoperating seamlessly with Java and running on the latest JVM.
 
  • #3
Hey geouke and welcome to the forums.

Funnily enough depending on the type of work, you have positions which are known as 'legacy programmers', which deal with working with and maintaing codebases that are written in old languages and platforms. In these cases, solid experience with something like FORTRAN or even COBOL is a requirement for getting the job.

But the reason for using newer languages is many-fold and depends on the specific application.

One is functionality, another is potential for optimization (very good compilers especially for specific architectures are common for something like C++ as well as FORTRAN), another is readibility, another is flexibility, another is related to development time for creating applications, another is interoperability (using specific OS functionality, communicating with other programs through things like DLL's).

Interoperability is a very important one because nowadays, you have not only single programs using multiple libraries communicating together, but different applications in their own process space communicating together.

Finally, and this is a very important factor, has to do with the support of a particular language/technology/operating-system/library/standard. Having something as a standard is critical. Windows is good for developers because of the sheer amount of support that it gets not only from software developers, but also from the hardware vendors themselves. This is one reason why linux wasn't a popular thing in the past, because windows had a much better driver model and framework which is really nice for hardware vendors (not to mention that windows came prepackaged with every new PC and still does which entice hardware vendors to support windows).

When you factor all these kinds of things and the attitudes of software development as they progress and mature, you get the shift from things like FORTRAN to C++ to .NET to whatever the next generation of development environments will be.
 
  • #4
Yes, geouke, why not Fortran?!

For what you have in mind, there is absolutely nothing wrong with Fortran.

Some of the hype about teaching a particular new language at school which then drives the next generation of programmers to start writing software in another language is sometimes driven by novelty, fashion, or pure financial interest by an individual company. That's why schools, for various reasons, have gone from teaching Fortran to C to C++ to Java and now you see them including Python...talk about becoming the language of choice by your own merits without a marketing engine (Java, Sun Microsystems) behind you.

Fortran stands for FORmula TRANslation, and it was invented to do math.

C was invented to write Unix :-) and it is more of a systems kind of programming language.

C++ is object oriented programming and many people were getting hit with memory leak programs, etc.

Java was supposed to be answer to C++ problems.

Python...well, I let you read about Python.

In any case, in your field and in general for the sciences, Fortran is a lot more popular than the typical programmer thinks.

There is a lot legacy code, great long standing libraries that do all sort of linear algebra and other simulation that have been around so long that are now pretty much bug free...that's were part of the value is.

Also, typically, Fortran is more standardized than C...if somebody give a fortran library to something or there is a package out there from a given company, you can comile it along with your program and it typically incorporates a lot easier than if you were programming in C.

Fortran, for the longest time, did not suffer of memory leaks and things like that...I don't know if that trend continues or whether with Fortran 90 and 2003 with structures, pointers and allocation...it is starting to suffer too.

Anyway, I do program in Fortran and C...I would agree than Fortran is much simpler to learn and to program in.

And if you would learn Python...you could do a bunch of things...if it gets numeric intensive, you always wrap your fortran code by executing f2py and simply call your fortran from python.

Good luck.

gsal
 
  • #5
Thanks for all of your helpful replies!
 

1. Why is C preferred over Fortran for numerical analysis?

C is a high-level programming language that offers more flexibility and control over memory management, making it easier to optimize algorithms for numerical analysis. Fortran, on the other hand, is specialized for scientific computing and may not offer the same level of flexibility.

2. Does C have better performance than Fortran for numerical analysis?

While Fortran was historically known for its superior performance in scientific computing, modern C compilers have caught up and even surpassed Fortran in certain cases. Additionally, C's flexibility allows for more efficient use of resources, resulting in better performance overall.

3. Are there any specific features in C that make it better for numerical analysis compared to Fortran?

C offers a wide range of data types, such as floating-point numbers and complex numbers, which are essential for numerical analysis. It also has a robust set of built-in functions and libraries for mathematical operations, making it a powerful tool for this type of analysis.

4. What are some drawbacks of using Fortran for numerical analysis?

Fortran is a very specialized language, meaning it may not be as versatile or widely applicable as C. It also has a more rigid syntax, making it less intuitive for programmers who are not familiar with the language.

5. Is it possible to use both C and Fortran for numerical analysis in the same project?

Yes, it is possible to combine C and Fortran in a single project for numerical analysis. Many software packages and libraries, such as MATLAB, use a combination of both languages to take advantage of their respective strengths.

Similar threads

  • Programming and Computer Science
Replies
16
Views
1K
  • Programming and Computer Science
Replies
9
Views
1K
  • Programming and Computer Science
12
Replies
397
Views
13K
  • Programming and Computer Science
Replies
4
Views
1K
  • Programming and Computer Science
Replies
8
Views
880
  • Programming and Computer Science
Replies
6
Views
1K
  • Programming and Computer Science
Replies
1
Views
929
  • Programming and Computer Science
2
Replies
69
Views
4K
  • Programming and Computer Science
Replies
4
Views
4K
Back
Top