help-octave
[Top][All Lists]

## Re: memory exhausted, precision ok

 From: Daniel Heiserer Subject: Re: memory exhausted, precision ok Date: Wed, 29 Jul 1998 10:31:21 +0200

```A. Scottedward Hodel wrote:
>
> I ran the following code on 1 172x172 matrix:
>
> # truncate acd to 6 digits of precision...
> for ii=1:rows(acd)
>   for jj = 1:columns(acd)
>     eval(["acd(ii,jj) = ",sprintf("%12.6E",acd(ii,jj));]);
>   endfor
> endfor
>

Hi,
here is my solution of your precision stuff (no ideas about the memory):
------------------ chop ---------------------------
function back=precision(in,prec)
%  PRECISION(X,PREC)
%  precision chops some digits. The accuracy of
%  the output equals to prec. Default for prec is 6.
%  WARNING: works for real only

if (nargin <2)
prec=6;
disp('Warning using default precision.');
else
prec=floor(prec);
end
disp(['Precision is ',num2str(prec),' digits.']);
prec=prec-1;

% take care of the signature
signature=sign(in);
absin=abs(in);
% split into exponent and base
exponent=log(absin)./log(10);
digits=absin./10.^floor(exponent);

% well, no lets take the precision
digits=round(digits*10^prec)/10^prec;

% lets merge the stuff again
back=signature.*digits.*10.^floor(exponent);
---------------------- chop --------------------
--
Mit freundlichen Gruessen
Daniel Heiserer
-----
--------------------------------------------------------------
Daniel Heiserer, BMW AG, Knorrstrasse 147, 80788 Muenchen
Abteilung EK-20
Tel.: 089-382-21187, Fax.: 089-382-42820