long double with MATLAB?

boyfarrell

Registered
Hello everybody,

The internet seems to be a bit dry when it comes to this topic, but can MATLAB do long double math computations and functions? It's not obvious if it does...

Daniel.
 
Great,

I'll give that cast function a go. Think that page must have slipped me by when I looked, cheers.

Daniel.
 
To my knowledge, Matlab is limited to 64 bit doubles, and long double doesn't add any more precision. If you need more precision, you may want to take a look at this, a MATLAB interface for the GMP library.
 
Hi Viro,

It depend on how the long double is defined, this is hardware specific. PowerPC is defines it in such away so not to increase the range only the precision. However, long double on AMD (and may be intel) increases the range.

I have GMP installed on the Mac for my C apps but I didn't know about the matlab link, cheers I'll give it ago.

Dan.
 
Hi,

I'm up to the stage:

"...Then, in the @mp/private/ directory, start Matlab and run
mp_compile_all.m This will attempt to mex each of the *.c routines
in that directory..."

However, I don't think my LD_LIBRARY_PATH is set propertly.

Where do I set this? The LD_LIBRARY_PATH in xterm says /opt/local/include shouldn't it be /opt/local/lib as I want to include libgmp and libmpfr? If so how do I change this?

Cheers, Dan.
 
if you want to set the environment variables correctly, you can create a file in your $HOME directory called .matlab7rc.sh and add the definition for LD_LIBRARY_PATH there. This document should provide you with more details.
 
Great, I didn't spot that page when looking thanks very much. I have been messing around trying to find where exactly to update the path. Inside the .matlab7rc.sh file I found some instruction on how to edit the path and also the actual code where I need to make the changes.

Could somebody decode this into common-people-speak I can't figure out what it means! (I have tried adding /opt/local/lib at various points in this code but it either does nothing or prevents matlab from loading!

Instructions from .matlab7rc.sh:
Code:
LDPATH_PREFIX	(path(s) that appear at the
#					 start of LD_LIBRARY_PATH)
#
#			Enclose in single quotes to defer evaluation
#			to the MATLAB script.
#
#		   LDPATH_SUFFIX	(path(s) that appear at the
#					  end of LD_LIBRARY_PATH)
#
#			Enclose in single quotes to defer evaluation
#			to the MATLAB script.
#
#		   LD_LIBRARY_PATH	(load library path - the name
#					 LD_LIBRARY_PATH is platform
#					 dependent)
#
#			TABLE:
#
#			      platform          variable name
#			      --------          -------------
#				sol2		LD_LIBRARY_PATH
#				hpux		SHLIB_PATH
#				glnx86		LD_LIBRARY_PATH
#                               mac             DYLD_LIBRARY_PATH       
#
#		   NOTE: The final load library path determined
#			 in the MATLAB startup script is composed
#			 of:
#			
#       ------------------------------------------------------------
#       LDPATH_PREFIX:<matlab_additions>:LD_LIBRARY_PATH:\
#		      <system_additions>:LDPATH_SUFFIX
#       ------------------------------------------------------------
#
#			 This means to add paths between:
#			 1. <matlab_additions> and LD_LIBRARY_PATH
#			    put them in front of LD_LIBRARY_PATH
#			 2. LD_LIBRARY_PATH and <system_additions>
#			    put them at the end of LD_LIBRARY_PATH
#
Here is the point in the file that is specific to the mac when setting the library path variable:
Code:
	    LDPATH_PREFIX=''
#
# To always use the OpenGL libraries shipped with MATLAB uncomment the next
# line.
#
#           LDPATH_PREFIX='$MATLAB/sys/opengl/lib/$ARCH'
#
	    LDPATH_SUFFIX=''
#
	    if [ "$DYLD_LIBRARY_PATH" != "" ]; then
                DYLD_LIBRARY_PATH=/opt/local/lib$DYLD_LIBRARY_PATH
	    else
                DYLD_LIBRARY_PATH=
	    fi
Where in this code to I need to add the path /opt/local/lib, does it need to be inside '' ?
 
You can add the line DYLD_LIBRARY_PATH=/opt/local/lib:$DYLD_LIBRARY_PATH to the first line inside the if statement like you've done (just remember the ':' character, between /opt/local/lib and $DYLD_LIBRARY_PATH, or it won't work) and add DYLD_LIBRARY_PATH=/opt/local/lib to the line in the else clause.
 
Thanks for that have given it a go. It seems to have updated the varible:
Code:
DYLD_LIBRARY_PATH=/Applications/MATLAB7/sys/os/mac:/Applications/MATLAB7/bin/mac:/Applications/MATLAB7/extern/lib/mac:/opt/local/lib:/opt/local/include:/Applications/MATLAB7/sys/opengl/lib/mac
However, when I try to compile it still tells me that it can't find the mpfr.h and gmp.h?

These are the header files for the librarys, it there another variable that I need to change so it knows where to find these? Should I put it in my environment.plist or my .profile? Or does MATLAB have some other PATH variable for header files?

Daniel.
 
Hmm... that's a tough one. I've never really used any external libraries with MEX before and the Matlab documentation is kinda sparse on the issue of include paths(!!). Perhaps you could try to make a symlink to the files in /usr/include? Something along the lines of
Code:
sudo ln -sf /opt/include/gmp.h /usr/include/gmp.h
sudo ln -sf /opt/include/mpfr.h /usr/include/mpfr.h
 
Hi,

I did something quite similar (though not a slick), I included the path to the header file in the #include of all the C source files... and guess what... it still doesn't work!

I'm going to give up at this point.

I have a few more ideas but, like manually compiling the gmp and mpfr librarys from source rather than using darwinports. That way I will find out if there is any error by running make check.

Apart from that, the guy that wrote the matlab toolbox did so on Red Hat so that's another option...

Cheers, for your help. I'll post if I find out anything.

Daniel
 
Back
Top