|
[Sponsors] |
June 28, 2008, 19:05 |
Fortran vs Matlab Help
|
#1 |
Guest
Posts: n/a
|
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 |
|
June 28, 2008, 21:15 |
Re: Fortran vs Matlab Help
|
#2 |
Guest
Posts: n/a
|
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)
|
|
July 2, 2008, 12:48 |
Re: Fortran vs Matlab Help
|
#3 |
Guest
Posts: n/a
|
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. |
|
July 2, 2008, 16:05 |
Re: Fortran vs Matlab Help
|
#4 |
Guest
Posts: n/a
|
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. |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
caling matlab in Fortran | HaKu | Main CFD Forum | 0 | July 16, 2009 16:35 |
MATLAB FORTRAN | Ally | Main CFD Forum | 4 | July 12, 2007 04:51 |
matlab to fortran | ztdep | Main CFD Forum | 4 | November 15, 2006 09:15 |
calling matlab from fortran | prasat | Main CFD Forum | 5 | February 4, 2003 17:04 |
C++, Fortran and Matlab | Wole F. | Main CFD Forum | 11 | September 26, 2000 11:01 |