function rod_opt_class % First solve using fmincon x0 = 10*ones(2,1); options = optimset('Display','iter','MaxIter',100,'MaxFunEvals',500,'LargeScale','off'); A = []; b = []; Aeq = []; beq = []; %lb = 0.1*ones(2,1); lb = []; ub = []; x = fmincon(@cost,x0,A,b,Aeq,beq,lb,ub,@constraints,options) pause % Now solve using fminsearch x = fminsearch(@augcost,x0,options) function f = cost(x) x1 = x(1,1); x2 = x(2,1); f = 120000/(x1*x2^2); function [c,ceq] = constraints(x) x1 = x(1,1); x2 = x(2,1); c = []; ceq = x1^2+x2^2-400; function f = augcost(x) x1 = x(1,1); x2 = x(2,1); cost = 120000/(x1*x2^2); penalty = (x1^2+x2^2-400)^2; w = 10; f = cost+w*penalty;