MATLAB Answers

How to increase the precision of Matlab (compared to Fortran) ???

8 views (last 30 days)
Zheng
Zheng on 17 Nov 2012
Hi,
I am using Matlab to translate subroutines coded by FORTRAN. However I found that the truncation error of matlab is very important, it means the precision of matlab can not be comprared to Frotran.
I tried format command, it does not work. Anyone knows how to increase the precision of matlab?
Regards
Zheng Li
  1 Comment
Jan
Jan on 18 Nov 2012
The question would be more clear, if you explain "truncation error of Matlab is very important" with an explicit example. Currently it seems, like you confuse the internal representation of numbers (double is exactly the same as real*8) and the output to the command window (affected by the format command).

Sign in to comment.

Answers (3)

Walter Roberson
Walter Roberson on 18 Nov 2012
MATLAB's "double" has the same precision as Fortran's REAL*8.
MATLAB does not have a numeric class equivalent to REAL*16.

Ben Barrowes
Ben Barrowes on 18 Nov 2012
What do you mean when you say "compare"? "format long" in matlab should give many digits of display. In any case, like Strider says, matlab default double is the same precision as fortran's real*8. If you need arbitrary precision in matlab (but slow calculation) try the multiple precision toolbox:
If you are converting fortran to matlab, try f2matlab:
it can get you 95% of the way to working m-code.

Pavel Holoborodko
Pavel Holoborodko on 20 Jul 2013
This addon: Multiprecision Computing Toolbox for MATLAB allows programming with arbitrary precision.
It also provides fast quadruple precision mode (equivalent to REAL*16) in particular.
  8 Comments
Jan
Jan on 31 Jul 2013
@Wendy: Thanks, this clears my question completely and I've removed the my flag.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!