0

I'd like to be able to control the decimal accuracy exactly while iterating a chaotic map. In particular, I'd like to make sure that Matlab uses no more / no less than the value p I specify in the following function:

function out = chaotic_logistic(seed,n,p,varargin)
%Returns a vector containing the seed and n iterations 
%of the logistic map: u*x*(1-x), which is chaotic on the
%unit interval when u is contained in (~3.56995,4)

%If a third argument is passed, this will be used as the u parameter.
%Otherwise u=4 by default.

%Finally, if 'last' is passed as the fourth argument, only the last
%iteration will be returned.

%NOTE: As currently designed, this function can be broken 
%by passing 'last' as the THIRD argument, etc. SO BE CAREFUL OR FIX IT.

digits(p) %sets desried accuracy to p decimal places??

if length(varargin)>=1 %default param 
    param = varargin{1};
else
    param = 4;
end

out = [seed zeros(1,n-1)]; %preallocate

apply_fcn = vpa(seed); %see vpa doc??

for i=1:n-1
    apply_fcn = vpa(param.*apply_fcn.*(1-apply_fcn)); %note vpa again
    out(i+1) = apply_fcn;
end

if length(varargin)==2 && strcmp(varargin{2},'last')
    out = out(end);
end

If I understand correctly, digits() should do the trick, but I'm not sure and it's crucial that I have the accuracy as specified when I call the function (as anyone familiar with chaos will know!).

Thanks in advance!

rayryeng
  • 102,964
  • 22
  • 184
  • 193
caseyalan
  • 3
  • 3
  • In the doc of [`digits`](http://www.mathworks.fr/fr/help/symbolic/digits.html), it's precisely said that: `The number of digits that you specify using the vpa function or the digits function is the guaranteed number of digits. Internally, the toolbox can use a few more digits than you specify. These additional digits are called guard digits`. – Bentoy13 Aug 06 '14 at 14:58
  • Wow I read the wrong doc yesterday. I'm so sorry anyone wasted their time here! Thanks @Bentoy13 – caseyalan Aug 06 '14 at 15:41
  • Very small waste of time, and I've learned something, so I've been rewarded :) – Bentoy13 Aug 06 '14 at 16:15

0 Answers0