function [f,g,H] = fig31fun(x)
% FIG31FUN A function that looks like Figure 3.1 from Nocedal and Wright

fx = @(x)-10.*sin(x).*(sqrt(x)-1).^2+0.5*exp(-20*(x-0.2).^2)+0.1*exp(-20*(x-1).^2);
% Computed with Matlab's symbolic toolbox
gx = @(x) exp((x-1.0./5.0).^2.*-2.0e1).*(x.*4.0e1-8.0).*(-1.0./2.0)-exp((x-1.0).^2.*-2.0e1).*(x.*4.0e1-4.0e1).*(1.0./1.0e1)-cos(x).*(sqrt(x)-1.0).^2.*1.0e1-1.0./sqrt(x).*sin(x).*(sqrt(x)-1.0).*1.0e1;
Hx = @(x) exp((x-1.0).^2.*-2.0e1).*-4.0-exp((x-1.0./5.0).^2.*-2.0e1).*2.0e1-(sin(x).*5.0)./x+sin(x).*(sqrt(x)-1.0).^2.*1.0e1+exp((x-1.0./5.0).^2.*-2.0e1).*(x.*4.0e1-8.0).^2.*(1.0./2.0)+exp((x-1.0).^2.*-2.0e1).*(x.*4.0e1-4.0e1).^2.*(1.0./1.0e1)-1.0./sqrt(x).*cos(x).*(sqrt(x)-1.0).*2.0e1+1.0./x.^(3.0./2.0).*sin(x).*(sqrt(x)-1.0).*5.0;

f = fx(x);
g = gx(x);
H = Hx(x);

if nargout==0
    clf;
    subplot(2,1,1);
    c1 = 0.1;
    c2 = 0.4;
    f0 = fx(0.05);
    g0 = gx(0.05);
    ezplot(fx,[0.05,3]);
    yl = ylim
    hold on;
    ezplot(@(x) f0 + c1*x*g0,[0.05,3])
    hold off;
    ylim(yl);
    
    
    subplot(2,1,2);
    ezplot(gx,[0.05,3]);
    line([0.05,3],[c2*g0 c2*g0]);
end