Search code examples
juliacalculusgadfly

Plot real-valued function with variable parameters


This question sounds more difficult than it actually is.

I wonder, how I can plot a mathematical function with julia?

Until now I used Gadfly to plot. I now want to play around with a function (constrained optimization on convex functions) but I can't find a way to define it.

E.g. I want to do:

plot( layer(y=x^2+1 …), layer(y=(x-4)+(x+3),…),…)

I know that there is a optimization package, however I want to understand and therefore do it myself. For that I just want to be able to draw any function (also multivariate functions).

So, how can I do this? Is this even possible in Gadfly or do I need to use another plotting library?

Any help is greatly appreciated.


Solution

  • See plotting functions and expressions in the Gadfly manual.

    For your example, something like plot([x->x^2+1, x->(x-4)+(x+3)], -2, 2) should do the trick using anonymous functions.

    example plot

    It's not currently possible to do this with multivariate functions as far as I'm aware.