function h = stepsize(A) % h = stepsize(A) % find approximate STEP SIZE for Continuous-time system simulations % if A is a MATRIX it is assumed to be the system matrix % if A is a ROW VECTOR it is assumed to be the characteristic equation % if A is a COLUMN VECTOR it is assumed to be the system's poles % h = approximate step size to use for time response computations % Written by: Duane Hanselman, University of Maine, (207)-581-2246 [m,n] = size(A); if m == n, poles = eig(A); end if n == 1, poles = A; end if m == 1, poles = roots(A); end rp = real(poles) + eps; ip = imag(poles); [m,i] = max(ip./rp); h = min( [ -2/min(rp), 0.2*pi/max([abs(ip(i)),eps]) ] );
Perform translation:
mfile2sci stepsize.mResulting code put in stepsize.sci:
function [h]=stepsize(A) h=[]; // h = stepsize(A) // find approximate STEP SIZE for Continuous-time system simulations // if A is a MATRIX it is assumed to be the system matrix // if A is a ROW VECTOR it is assumed to be the characteristic equation // if A is a COLUMN VECTOR it is assumed to be the system's poles // h = approximate step size to use for time response computations // Written by: Duane Hanselman, University of Maine, (207)-581-2246 [m,n] = size(A); if m==n then poles = spec(A); end if n==1 then poles = A; end if m==1 then %v1 = A poles = roots(poly(%v1($:-1:1),'x')); end rp = real(poles)+%eps; ip = imag(poles); [m,i] = mtlb_max(ip./rp); // mtlb_e(ip,i) may be replaced by ip(i) if ip is a vector. h = min([-2/mtlb_min(rp),0.2*%pi/max([abs(mtlb_e(ip,i)),%eps])]);