function d=torex(t,y)
% torex(t,y) evaluates the (3 dimensional) vector field of Example 17.2
% in Hale-Kocak which exhibits invariant tori.
% parameter=[lambda,b,c,d] (global).

global parameter
lb=parameter*[1;-1;0;0];
r=y(3)+parameter(4)*(1-y(3)^2);
d=[lb*y(1)-parameter(3)*y(2)+y(1)*r;parameter(3)*y(1)+y(2)*(lb+r);parameter(1)*y(3)-dot(y,y)];
% M. Day, May 8, 2012