function [f, g, t1, t2, coeff1] = toptimf(X, coeff1, coeff2, coeff3)
%TOPTIMF Test functions for optimization test-suite (TOPTIM).
if (nargin > 2)
	if coeff2 == 7 % 1D seminf
		if isnan(coeff1(1,1)), coeff1 = [0.2  0; 0.2 0]; end
		% Sample set
		w1=1:coeff1(1,1):100;
		w2=1:coeff1(2,1):100;
		% Semi-infinite constraints
		t1=sin(w1*X(1)).*cos(w1*X(2))-1/1000*(w1-50).^2-sin(w1*X(3))-1-X(3);
		t2=sin(w2*X(2)).*cos(w2*X(1))-1/1000*(w2-50).^2-sin(w2*X(3))-1-X(2);
		%plot(w1,t1,w1,t1,'o',w2,t2,w2,t2,'+')
		g = []; % No constraints
		% Objective function
		f = sum((X-0.5).^2);
	elseif coeff2 == 8 % 2D seminf
		% Initial sampling intervals
		if isnan(coeff1(1,1)), coeff1 = [2  2]; end
		% Sampling sets
		w1=1:coeff1(1,1):100;
		w2=1:coeff1(1,2):100;
		[wx, wy] = meshdom(w1, w2);
		% Old meshdom:
		wx = w1(ones(length(w2), 1),:);
		w2t = w2(length(w2):-1:1)'; 
		wy = w2t(:,ones(1, length(w1)));
		% Semi-infinite  constraint
		t1=sin(wx*X(1)).*cos(wy*X(2)) -1/1000*(wx-50).^2-sin(wx*X(3))-1-X(3) + ...
      		sin(wy*X(2)).*cos(wx*X(1))-1/1000*(wy-50).^2-sin(wy*X(3))-1-X(2);
		% Objective function
		f = sum((X-0.2).^2);
		t2 = coeff1;
	end
elseif coeff1==1 % Unconstrained
	f=100*(X(2)-X(1)^2)^2+(1-X(1))^2;
elseif coeff1 ==2 % Constrained Pg 74 Schittkowski
	f(1)=-X(1)*X(2)*X(3);               
	g(1)=-X(1)-2*X(2)-2*X(3);
	g(2)=X(1)+2*X(2)+2*X(3)-72;  
elseif coeff1 ==3 % Goal attainment 
	A=[-0.5 0 0    
	0    -2 10
	0   1  -2];
	B=  [1 0
	-2 2
	0 1];
	C = [1 0 0
	0 0 1];
	f=sort(eig(A+B*X*C));
elseif coeff1 == 4 % Minimax
	f(1)=2*X(1)^2+X(2)^2-48*X(1)-40*X(2)+304; 
	f(2)=-X(1)-3*X(2);
	f(3)=-18+X(1)+3*X(2);
	f(4)=-X(1)-X(2);
	f(5)=-8+X(1)+X(2);
elseif coeff1 == 5 % Non-linear least squares problem
	for i=1:10
		f(i)=2+2*i-exp(X(1)*i)-exp(X(2)*i);
	end
elseif coeff1 == 6 % Solve  problem
	x2=zeros(2);
	x2(:)=X;
	f=x2*x2*x2-[1,2;3,4];
	f=f(:);
elseif coeff1 == 9 % fmin  problem
	f = sin(X);
end
