view sequences/expdata.m @ 6:0ce3c2070089

Removed duplicate code and fixed doc in timed_action.
author samer
date Mon, 14 Jan 2013 14:33:37 +0000
parents 3f77126f7b5f
children b1280319413e
line wrap: on
line source
function y=expdata(A,B,N,M)
% expdata - exponential data sequence
%
% expdata :: 
%    real  ~'initial value',
%    real  ~'final value',
%    natural ~'number of steps (sequence length is steps+1),
%    M:natural ~'buffer size'
% -> seq [[1,M]].

	if nargin<4, M=1; end

	lA=log(A);
	k=(log(B)-lA)/N;
	y=unfoldseq(@ls1,0:M-1);

	function [X,I]=ls1(I), 
		surp=I(end)-N;
		if surp>=0,
			X=exp(lA+k*I(1:end-surp)); 
			if surp<M, X(end)=B; end
		else
			X=exp(lA+k*I); 
		end
		I=I+M; 
	end
end