CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > General Forums > Main CFD Forum

Fortran vs Matlab Help

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   June 28, 2008, 19:05
Default Fortran vs Matlab Help
  #1
idee
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

  Reply With Quote

Old   June 28, 2008, 21:15
Default Re: Fortran vs Matlab Help
  #2
Paolo Lampitella
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)
  Reply With Quote

Old   July 2, 2008, 12:48
Default Re: Fortran vs Matlab Help
  #3
Brendan
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.
  Reply With Quote

Old   July 2, 2008, 16:05
Default Re: Fortran vs Matlab Help
  #4
idee
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.

  Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


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


All times are GMT -4. The time now is 17:35.