CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   Main CFD Forum (http://www.cfd-online.com/Forums/main/)
-   -   Fortran vs Matlab Help (http://www.cfd-online.com/Forums/main/15350-fortran-vs-matlab-help.html)

 idee June 28, 2008 18:05

Fortran vs Matlab Help

Am having a problem with my code. Am doing simulation for a system of PDEs. I managed to get results using Matlab after ages of time. I decided to do the simulation in fortran. The question now:

Is it necessarily that I will get the same numerical results?

thanks

 Paolo Lampitella June 28, 2008 20:15

Re: Fortran vs Matlab Help

It's nearly impossible that you have the same numerical results but you should have some control over this, that is you should be able to control up to which digit the results will be the same (e.g. the tollerance of an iterative solver, the precision of the variables in fortran and so on)

 Brendan July 2, 2008 11:48

Re: Fortran vs Matlab Help

The code structure in Matlab and Fortran is very similar, Matlab is a great way to prototype code that you want to run in Fortran (which, in my experience, is much faster).

You can pretty much change a Matlab code to Fortran using the find/replace option. Your results should be essentially the same but you will rarely get complete agreement. From experience the differences are around the order of machine accuracy (it's to do with the way that matlab and fortran deal with real numbers).

One piece of advice - if you're trying to change a code from matlab to fortran be careful with the loop structure:

Matlab: for I=1:10 ..... end

Fortran: DO I=1,10 ....... ENDDO

If you accidently use "I=1:10" in Fortran it means something entirely different.

A good way to check your solution is to subtract your matlab solution from the fortran one and plot the results - if the difference is small (1e-14 ish) then your results are the same.

 idee July 2, 2008 15:05

Re: Fortran vs Matlab Help

Many thanks your support very much appreciated.

I finally managed to get results it is the same behavior but there is a difference. In other words the fortran code was able to capture discontinuity, according to the method am using of course, in a better way and fast enough. May be am having problems with things from matlab to fortran e.g.

R=zeos(k,2)

R=ones(k,2)

R=find(r1>=r2)........

w1=max(max(find(w3>w4)))....

Many thanks for your help.

 All times are GMT -4. The time now is 18:59.