In [2]:
using Plots
pyplot(tickfont=font("sans-serif"), titlefont=font("sans-serif"), legendfont=font("sans-serif"))


Out[2]:
Plots.PyPlotBackend()

In [3]:
# Let's demonstrate a failure of optimality condition.
# Consider this function
f = (x, y) -> (y - x.^2).*(y - 3*x.^2)
# Create a meshgrid
x = -6:0.05:6
y = -6:0.05:6
X = repmat(x', length(y), 1)
Y = repmat(y, 1, length(x))
# Evaluate each f(x, y)
Z = map(f, X, Y)

plot3d(X, Y, Z, seriestype=:surface)
#zlims!(0,50.0)


Out[3]:

In [4]:
# Show the plot in log-space
plot3d(X, Y, log(Z-minimum(Z)+sqrt(eps(1.0))), seriestype=:surface)


Out[4]:

In [ ]:


In [5]:
plotly()
t = π
zt = -5:5

ftheta = z -> f(z*cos(t), z*sin(t))

# create a layout
l = @layout [a{0.5w} b]
p = plot(x, y, Z, st=:contour, layout=l)

plot!(p[1], zt*cos(t), zt*sin(t), line=(:red, 2))

z = -5:0.01:5
zf = map(ftheta, z)
plot!(p[2], z, zf, xaxis=[-5, 5], ylims=[-3, 8])