function [f,g]=trimfun(DES,x0,u0,y0,ix,iu,iy,dx0,idx,evalstr,t)
%TRIMFUN Used as a gateway to the optimization routine CONSTR
%	This function is used in trimming. See TRIM.

%	Copyright (c) 1990-94 by The MathWorks, Inc.
%	Andrew Grace 11-12-90.

	nx=length(x0);
	x = DES(1:nx);
	u = DES(nx+1:nx+length(u0));
	lambda = DES(length(DES));

% Get derivatives and outputs from system.
	flag = 3; 
	eval(evalstr)
	y = ret; 
	flag = -1; 
	eval(evalstr)
	dx = ret; 
	
% Form constraints that minimize deviation from intended values.
	gg=[x(ix)-x0(ix);y(iy)-y0(iy);u(iu)-u0(iu)];
	g=[dx(idx)-dx0(idx); gg-lambda; -gg-lambda];

% Objective function is just lambda.
	f=lambda;


