Tlim = 1400;

var0 = [106.57, 0.00104];

lb =  [50.0, 0.0010];
ub = [250.0, 0.0050];

lbscal = -ones(size(lb));
ubscal =  ones(size(ub));
vscal0 = 2*(var0-lb)./(ub-lb)-1;

options = optimset('Display','iter','LargeScale','off', ...
		   'GradObj','on', 'GradConstr','on', ...
		   'TolCon',0.00001,'TolFun',0.00001,'TolX',0.00001);

[vscal, fval] = fmincon(@mdot, vscal0, [], [], [], [], lbscal, ...
			 ubscal, @condif, options, lb, ub, Tlim);

% Check how well constraints are met (i.e. find Twall)
[CC, CCeq] = condif(vscal, lb, ub, Tlim);
Tmax = Tlim*(CCeq+1);

desvar = lb + 0.5*(1 + vscal).*(ub-lb);

fprintf(1,'Final result from optimization\n');
fprintf(1,'Ucool = %10.5f m/s\n',desvar(1));
fprintf(1,'h     = %10.5f m\n',  desvar(2));
fprintf(1,'Tmax  = %10.5f K', Tmax);

