Thread Subject: format change for computation not display

Subject: format change for computation not display

From: Uwe Brauer

Date: 28 May, 2008 13:44:01

Message: 1 of 10

Hello

according to
http://www.mathworks.com/access/helpdesk/help/techdoc/index.html?/access/helpdesk/help/techdoc/ref/format.html.
The format function affects only how numbers are displayed,
not how MATLAB computes or saves them.

so the question is, how can I change the format which uses
Matlab for its computation?????

thanks

Uwe Brauer

Subject: format change for computation not display

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 28 May, 2008 13:59:04

Message: 2 of 10

In article <g1jnj1$4db$1@fred.mathworks.com>,
Uwe Brauer <oub@mat.ucm.es> wrote:

>according to
>http://www.mathworks.com/access/helpdesk/help/techdoc/index.html?/access/helpdesk/help/techdoc/ref/format.html.
>The format function affects only how numbers are displayed,
>not how MATLAB computes or saves them.

>so the question is, how can I change the format which uses
>Matlab for its computation?????

In general, you do not: if you need to work with (say) single precision
instead of double precision, then you convert the type of the numbers
and then Matlab will automatically work with the new type. For example,

foo = rand(3,5); %foo contains double precision numbers.
foof = single(foo); %foof contains the numbers as single precision.
%now work with foof


On some platforms, you can use

  system_dependent('setprecision',24);

(or 53, or 80). And it might not work in the next version, as
system_dependent() is an officially undocumented function subject
to rapid change.
--
  "Allegories are in the realm of thoughts, what ruins are in
  the realm of things." -- Walter Benjamin

Subject: format change for computation not display

From: Uwe Brauer

Date: 28 May, 2008 14:56:02

Message: 3 of 10

roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson) wrote in
message <g1jof8$1va$1@canopus.cc.umanitoba.ca>...
> In article <g1jnj1$4db$1@fred.mathworks.com>,
> In general, you do not: if you need to work with (say)
single precision
> instead of double precision, then you convert the type of
the numbers
> and then Matlab will automatically work with the new type.
For example,
>
> foo = rand(3,5); %foo contains double precision numbers.
> foof = single(foo); %foof contains the numbers as single
precision.
> %now work with foof

thanks,

that helps a little, but I wanted was even more
primitive, that is to work only with 4 significant digits.

it seems to be impossible to achive this in Matlab

>
>
> On some platforms, you can use
>
> system_dependent('setprecision',24);
>

it would be nice if setprecision would allow even lower
values.

regards

Subject: format change for computation not display

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 28 May, 2008 16:07:49

Message: 4 of 10

In article <g1jrq2$1fb$1@fred.mathworks.com>,
Uwe Brauer <oub@mat.ucm.es> wrote:

>that helps a little, but I wanted was even more
>primitive, that is to work only with 4 significant digits.

>it seems to be impossible to achive this in Matlab

Sounds like you might want the Fixed-Point Toolbox.

Alternately, if you have the Symbolic Toolbox, you could do
all of your calculations with it, using digits(4).

I would not be positive, though, that the Symbolic Toolbox would use
those number of digits at *all* levels -- for example, if
it is calculating sin() and hits 9! in the denominator of a term, then
working with four significant digits consistantly would require
that the 9! = 362880 be rounded to 362900. I'm not sure that the
resulting formulae would even be guaranteed to converge.
--
  "Walter exemplified class." -- Paul Tagliabue

Subject: format change for computation not display

From: Steven Lord

Date: 28 May, 2008 16:08:12

Message: 5 of 10


"Uwe Brauer" <oub@mat.ucm.es> wrote in message
news:g1jrq2$1fb$1@fred.mathworks.com...
> roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson) wrote in
> message <g1jof8$1va$1@canopus.cc.umanitoba.ca>...
>> In article <g1jnj1$4db$1@fred.mathworks.com>,
>> In general, you do not: if you need to work with (say)
> single precision
>> instead of double precision, then you convert the type of
> the numbers
>> and then Matlab will automatically work with the new type.
> For example,
>>
>> foo = rand(3,5); %foo contains double precision numbers.
>> foof = single(foo); %foof contains the numbers as single
> precision.
>> %now work with foof
>
> thanks,
>
> that helps a little, but I wanted was even more
> primitive, that is to work only with 4 significant digits.

If you want to work with fixed-point arithmetic you could use Fixed-Point
Toolbox:

http://www.mathworks.com/products/fixed/

but I think that deals with certain bit lengths in the exponent and
mantissa, not (I believe) significant digits.

Alternately, you could try using a small Digits value in Symbolic Math
Toolbox:

http://www.mathworks.com/access/helpdesk/help/toolbox/symbolic/digits.html

Out of curiosity, why do you only want to operate with 4 significant digits?

--
Steve Lord
slord@mathworks.com


Subject: format change for computation not display

From: Uwe Brauer

Date: 28 May, 2008 16:24:02

Message: 6 of 10

"Steven Lord" <slord@mathworks.com> wrote in message <g1k01c$qg9$1@fred.mathworks.com>...
> >
> > that helps a little, but I wanted was even more
> > primitive, that is to work only with 4 significant digits.
>
> If you want to work with fixed-point arithmetic you could use Fixed-Point
> Toolbox:
>
> http://www.mathworks.com/products/fixed/
>
> but I think that deals with certain bit lengths in the exponent and
> mantissa, not (I believe) significant digits.
>
> Alternately, you could try using a small Digits value in Symbolic Math
> Toolbox:
>
thanks I will try both.

> http://www.mathworks.com/access/helpdesk/help/toolbox/symbolic/digits.html
>
> Out of curiosity, why do you only want to operate with 4 significant digits?
>
oh this I need for some didatic examples for students in numerical analysis.


1 trying to solve a linear system with different types of
pivoting. The advantage of certain pivoting can be seen better with a low number of significant digits (as a matter of fact most text books examples use that (but of course most of them are old and the examples are maybe more than 30 years old))
2 trying to solve a linear system with a matrix which is very bad conditioned, say its number is 50000.


Regards


Subject: format change for computation not display

From: carlos lopez

Date: 1 Jun, 2008 00:12:02

Message: 7 of 10

"Uwe Brauer" <oub@mat.ucm.es> wrote in message
<g1jnj1$4db$1@fred.mathworks.com>...
> Hello
>
> according to
>
http://www.mathworks.com/access/helpdesk/help/techdoc/index.html?/access/helpdesk/help/techdoc/ref/format.html.
> The format function affects only how numbers are displayed,
> not how MATLAB computes or saves them.
>
> so the question is, how can I change the format which uses
> Matlab for its computation?????
>
> thanks
>
> Uwe Brauer
Check if the Multiple Precision Toolbox by Ben Barrowes fits
your needs. It is available on the FEX
Regards
Carlos

Subject: format change for computation not display

From: Uwe Brauer

Date: 1 Jun, 2008 13:23:01

Message: 8 of 10

"carlos lopez" <clv2clv_00000000_@adinet.com.uy> wrote in
message <g1spgi$mpu$1@fred.mathworks.com>...
> "Uwe Brauer" <oub@mat.ucm.es> wrote in message
> <g1jnj1$4db$1@fred.mathworks.com>...
> > Hello
> >
> > according to
> >
> > Uwe Brauer
> Check if the Multiple Precision Toolbox by Ben Barrowes fits
> your needs. It is available on the FEX
> Regards
> Carlos

Thanks that sounds very promising. I wil try it out.

Uwe

Subject: format change for computation not display

From: Image Analyst

Date: 1 Jun, 2008 13:47:01

Message: 9 of 10

"Uwe Brauer" <oub@mat.ucm.es> wrote in message <g1jnj1
$4db$1@fred.mathworks.com>...
> Hello
>
> according to
>
http://www.mathworks.com/access/helpdesk/help/techdoc/index.
html?/access/helpdesk/help/techdoc/ref/format.html.
> The format function affects only how numbers are
displayed,
> not how MATLAB computes or saves them.
>
> so the question is, how can I change the format which uses
> Matlab for its computation?????
>
> thanks
>
> Uwe Brauer
---------------------------------------------
Uwe:
If you just have a few numbers that you want to do this
with, you don't need to buy any additional toolboxes. Just
do this (example for 4 decimal places):
quantizedVariable = round(fullPrecisionVariable * 10000) /
10000;
Hopefully that's self explanatory.
It will involve creating an additional variable but that
additional variable will be chopped off at the number of
decimal places you designate.
Regards,
ImageAnalyst

Subject: format change for computation not display

From: Roger Stafford

Date: 2 Jun, 2008 02:27:01

Message: 10 of 10

"Image Analyst" <imageanalyst@mailinator.com> wrote in message <g1u98l
$rj6$1@fred.mathworks.com>...
> If you just have a few numbers that you want to do this
> with, you don't need to buy any additional toolboxes. Just
> do this (example for 4 decimal places):
> quantizedVariable = round(fullPrecisionVariable * 10000) /
> 10000;
> Hopefully that's self explanatory.
> It will involve creating an additional variable but that
> additional variable will be chopped off at the number of
> decimal places you designate.
> Regards,
> ImageAnalyst
----------
  That works only for numbers in a certain limited range. For general cases,
you would need to use the following. Let x be the number in question and
you want d digits of precision.

 n = floor(log10(x))-p+1;
 y = round(x/10^n)*10^n;

y is the desired nearest number to x with d significant digits.

  Note however, that such number will not be exact. For example, if you do
this to pi with 5 significant digits, getting 3.1416, the number you get will
not be precisely 3.1416 because of the limitations in double precision
floating point numbers. To be precise it will be:

 y = 3.14159999999999994813

Roger Stafford


Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
quantization Image Analyst 1 Jun, 2008 09:50:10
precision Image Analyst 1 Jun, 2008 09:50:09
arbitrary precision carlos lopez 31 May, 2008 20:15:07
rssFeed for this Thread

Public Submission Policy

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.

Contact us at files@mathworks.com