For Programmers: Free Programming Magazines  


Home > Archive > Matlab > July 2006 > limit decimals









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author limit decimals
bru

2006-07-13, 4:11 am

Dear friends,

Is there any way to limit the decimals?

Thank you
Dan Pearce

2006-07-13, 4:11 am

see

help format

and look at long and short
bru

2006-07-13, 8:06 am

Thanks!!!

But i have to use it before i use each variable or i can put it in
some way that will be used for all?

Dan Pearce wrote:
>
>
> see
>
> help format
>
> and look at long and short

Dan Pearce

2006-07-13, 8:06 am

I'm guessing you are looking for something like 'int', 'double',
'float' etc...

As it says at the top of the 'help format' comment

"All computations in MATLAB are done in double precision.
FORMAT may be used to switch between different output"

so there isn't anything you will be able to change other than the way
the results of calculation are displayed or saved.

Why were you looking to change it? Maybe we can help you more if we
know a bit more about your problem
bru

2006-07-13, 8:06 am

The problem is that i'm making a program to calculate the transfer
function and the Zin of a subscriber loop... i have to make a lot of
operations and some people wants it with a lot of precision (a lot of
more operations..). If i do this, the pc needs a lot of ram and goes
very slow. I want to try to reduce the decimals because maybe in this
way i make that the program runs faster...
Thanks a lot and sorry for my bad english !

Dan Pearce wrote:
>
>
> I'm guessing you are looking for something like 'int', 'double',
> 'float' etc...
>
> As it says at the top of the 'help format' comment
>
> "All computations in MATLAB are done in double precision.
> FORMAT may be used to switch between different output"
>
> so there isn't anything you will be able to change other than the
> way
> the results of calculation are displayed or saved.
>
> Why were you looking to change it? Maybe we can help you more if we
> know a bit more about your problem

Dan Pearce

2006-07-13, 8:06 am

Obviously I don't know your problem, but I am not sure how you can
have "some people want it with a lot of precision" as a problem and
then "try to reduce the decimals" as a possible resolution. It seems
a little counter intuitive to me.

If you have problems with speed then you should be looking to
vectorise as much of your code as possible, or even to try and split
your operations down so that they do not demand so much RAM at one
time.
Aditya vedantam

2006-07-13, 8:06 am

bru wrote:[color=darkred]
>
>
> The problem is that i'm making a program to calculate the transfer
> function and the Zin of a subscriber loop... i have to make a lot
> of
> operations and some people wants it with a lot of precision (a lot
> of
> more operations..). If i do this, the pc needs a lot of ram and
> goes
> very slow. I want to try to reduce the decimals because maybe in
> this
> way i make that the program runs faster...
> Thanks a lot and sorry for my bad english !
>
> Dan Pearce wrote:
'double',[color=darkred]
the[color=darkred]
if[color=darkred]
> we

Just put,
format short e %for 5 digit precision
or
format long e %for 15 digit precision
at the top of your m-file(program).
Aditya vedantam

2006-07-13, 8:06 am

Aditya vedantam wrote:
>
>
> bru wrote:
> transfer
lot[color=darkred]
> lot
in[color=darkred]
> 'double',
than[color=darkred]
> the
more[color=darkred]
> if
>
> Just put,
> format short e %for 5 digit precision
> or
> format long e %for 15 digit precision
> at the top of your m-file(program).


Yeah but,"trying to reduce the decimals" is no way to increase
computational speed.Try vectorizing the code.
Dan Pearce

2006-07-13, 8:06 am

> Aditya vedantam wrote:

> Just put,
> format short e %for 5 digit precision
> or
> format long e %for 15 digit precision
> at the top of your m-file(program).


This wont speed up the code. All computations in MATLAB are done in
double precision! This only changes the accuracy to which the results
displayed
bru

2006-07-13, 8:06 am

Aditya vedantam wrote:
> Yeah but,"trying to reduce the decimals" is no way to increase
> computational speed.Try vectorizing the code.



How can i do this? ^o)
Aditya Vedantam

2006-07-15, 7:02 pm

bru wrote:
>
>
> Aditya vedantam wrote:
>
>
> How can i do this? ^o)


Dear bru,
Search for "Matlab vectorization" or read up about vectorization in
the matlab help files.
Praveen

2006-07-15, 7:02 pm

Hi,

Is the vectorization unique to MATLAB or can be equally applied to C
codes as well?

Thanks

======

Aditya Vedantam wrote:
>
>
> bru wrote:
> increase
>
> Dear bru,
> Search for "Matlab vectorization" or read up about vectorization in
> the matlab help files.

Chris

2006-07-20, 8:05 am

Erik S wrote:[color=darkred]
>
>
> Not all computations in MATLAB are done in double precision. If
> you,
> for example, multiply two variables of type single the
> corresponding
> arithmetic will be in single precision. help format in R2006a
> yelds:
> FORMAT does not affect how MATLAB computations are done.
> Computations
> on float variables, namely single or double, are done in
> appropriate
> floating point precision, no matter how those variables are
> displayed.
>
> You can verify that arithmetics in single precision is faster than
> double by typing:
> This takes about 1.81 seconds on my machine. Compare this with
> which takes about 0.81 seconds.
> Vectorization techiniques is good ideas. If your data contains a
> lot
> of zeros, consider using sparse data types (help sparse).
>
> /Erik
> Dan Pearce wrote:
done[color=darkred]
> in


Is it possible to change from double to single in Matlab, so all
calculations are made in single instead of double? this would speed
up simulations a lot.

//Chris
Andrew Catellier

2006-07-25, 7:04 pm

Chris wrote:
> Is it possible to change from double to single in Matlab, so all
> calculations are made in single instead of double? this would speed
> up simulations a lot.
>
> //Chris


This would indeed be very useful. Any insight?

Thanks,

Andrew
Andrew Catellier

2006-07-31, 7:17 pm

Andrew Catellier wrote:
>
>
> Chris wrote:
all[color=darkred]
> speed
>
> This would indeed be very useful. Any insight?
>
> Thanks,
>
> Andrew


Turns out there is no way to switch all calculations to be single
based. However most MATLAB functions are able to deal with singles,
and therefore as long as your simulation code is also compatible with
singles, single calculations/variables should "propagate" through the
code.

Hope this helps,

Andrew
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com