Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: FIXED: [was] Again: Matlab for Linux and SVD
Replies: 0  

Advanced Search

Back to Topic List Back to Topic List  
Loesche

Posts: 16
Registered: 12/7/04
FIXED: [was] Again: Matlab for Linux and SVD
Posted: Jun 5, 1997 4:39 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

Hi there,

yesterday I posted a summary about problems with SVD under Matlab for
Linux (see: Loesche SUMMARY: [was] Again: Matlab for Linux and SVD).
Now it seems we found a quite nice workaround for that problem.
Up to my knowledge the problems are caused by using an FPU which
does its calculations in extended precision on one hand and Matlab
using double precision all the time on the other.

Carlos Fonseca <fonseca@acse.shef.ac.uk> pointed out a possible
workaround by using the function __setfpucw(unsigned short fpu_cw)
which is documented/declared in /usr/include/i386/fpu_control.h.
Thanks to Carlos for that.
I wrote two short C-mex files. One for putting the FPU in double
precision mode and another one for putting it back in extended mode.
The source fpu_double.c is attached at the end.

Indeed, as the following transcript shows, this works - at least for
my problem.

NNMP19:[loesche] >matlab

< M A T L A B (R) >
(c) Copyright 1984-95 The MathWorks, Inc.
All Rights Reserved
Version 4.2c

Pedigree brian linus /rel/bld/matlab4/v4.2c/all/sandbox4/src Wed Apr 24
10:50:58 EDT 1996
NO FLEX
Apr 24 1996


Commands to get started: intro, demo, help help
Commands for more information: help, whatsnew, info, subscribe

>> load C_22
>> format long
>> svd(C_22)

??? Error using ==> svd
Solution will not converge.

>> norm(C_22)
??? Error using ==> norm
Solution will not converge.

>> fpu_double
>> svd(C_22)


ans =

1.00000000000000
1.00000000000000
1.00000000000000
1.00000000000000
1.00000000000000
0.99999999999999

>> norm(C_22)

ans =

1.00000000000000

>> fpu_extended
>> svd(C_22)

??? Error using ==> svd
Solution will not converge.

>> norm(C_22)
??? Error using ==> norm
Solution will not converge.

>> exit

As you see, when the FPU is in double precision mode, SVD and NORM
converge. Switching back to extended precision shows the old behavior,
i.e. SVD and NORM breaking down.
When Matlab is terminated, the FPU precision mode is put to extended
precision, regardless of what was used by Matlab.

Here fpu_double.c comes:

/* interface to routine __setfpucw in libc.so

Ralf Loesche, 5. Juni 1997 */

#include <stdio.h>
#include <math.h>
#include <mex.h>
#include <i386/fpu_control.h>

/* prototype for external routine */
extern void __setfpucw(unsigned short fpu_cw);

void mexFunction(int nargout,Matrix *argout[],int nargin,Matrix
*argin[]) {
unsigned short fpu_cw;

fpu_cw = 0x127f;
__setfpucw(fpu_cw);

}


You obtain fpu_extended.c by changing
fpu_cw = 0x127f;
to
fpu_cw = 0x137f;
.

TMW could even put this source code on their solution search Web page
for Solution Number: 5231.
I think one can use fpu_double in the Matlab startup script without
problems for the calculations done. Matlab uses double precision and
does not take advantage of an fpu providing 80 bit digits and
slightly higher precision.


Regards, Ralf Loesche

ps: I would like to see, how non-Intel FPU's act on this (like Cyrix
6x86, AMD K5/K6). With 100% Intel compatibility in mind, they
should work the same. I don't have access to a non-Intel PC.
Maybe someone can try that example.

pps: Even fpu_single can be done that way. However, I don't recommend
using it ;-)





Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.