Plot a Differential Equation or a 3 variable function

How do I plot a function with 3 variables, either in 3d or a 2d contour plot.

U(x,y)=16*log(x)+9*log(y)
1 Like

http://docs.juliaplots.org/latest/generated/gr/#gr-ref22
http://docs.juliaplots.org/latest/generated/gr/#gr-ref50

1 Like

https://docs.juliaplots.org/latest/generated/gr/#gr-ref50

1 Like

How about this?

using StatsPlots

U(x,y)=16*log(x)+9*log(y)

x = 0.1:0.1:2.0
y = 0.1:0.1:2.0
z = [U(i,j) for i in x, j in y]

p = plot(
    x,
    y,
    z,
    linetype=:wireframe,
    legend=false,
    xlabel="x",
    ylabel="y",
    zlabel="z"
)

plot!(
    x,
    y,
    z,
    linetype=:surface,
    legend=false,
    xlabel="x",
    ylabel="y",
    zlabel="z",
    alpha=0.8
)

test

1 Like

That should work. Is there a way to do a 2d contour plot?

Just call contour instead of plot and omit the linetype keyword argument. If you have a look at the links that @Jeff_Emanuel and @odow replied with you’ll find this very quickly. Just navigate to the section for your backend of choice (e.g. GR, Plotly) and push Ctrl + f on your keyboard; then, type contour and you can go straight to the section of the docs that demonstrate contour plot examples.

EDIT: actually, you can just do linetype=:contour and not change anything else.

1 Like

this looks good, but I don’t know how to limit the y range to positive values