0

我希望能够在迭代混沌地图时准确控制小数精度。特别是,我想确保 Matlab 使用的值不超过/不低于我在以下函数中指定的值 p:

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

如果我理解正确,digits()应该可以解决问题,但我不确定,并且在调用函数时具有指定的准确性至关重要(任何熟悉混乱的人都会知道!)。

提前致谢!

4

0 回答 0