我希望能够在迭代混沌地图时控制小数精度完全。特别是,我想确保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()
应该做到这一点,但我不确定,当我调用该函数时,我具有指定的准确性至关重要(正如任何熟悉的人一样)混乱会知道!)。
提前致谢!