% A script to run discrete time systems % % The system is of the form x(k+1) = f(x(k)) % % The function "f" is defined in a file called "rhs.m" % global RHSNAME; disp('Discrete time system'); setrhs; x0 = input('Please enter the initial vector -> '); % % we want x0 to be a row vector % [r,c] = size(x0); if (r==1), x0 = x0'; end; t0 = input('Please enter the starting time (default 0) -> '); if (isempty(t0)), t0=0; end; t1 = input('Please enter the ending time (default 10) -> '); if (isempty(t1)), t1=10; end; disp('Working.'); k = [t0:t1]'; n = length(k); x = zeros(n,length(x0)); x(1,:) = x0'; for j=2:n x(j,:) = feval(RHSNAME, x(j-1,:)')'; end; disp('Done! Plotting graph.'); plot(k,x,k,x,'o') disp('To plot phase space type: ') disp('2 dimensions: phase2d'); disp('3 dimensions: phase3d');