Menu

How to use composition of functions?

Help
2011-06-22
2012-10-16
  • Nobody/Anonymous

    Hi all,

    Is there any ways to define f, g, h first before plotting f(g(x,y),h(x,y)) =
    0?
    Where, for example, f(x,y) = x^2 + y^3 - xy, g(x,y) = 2x + 3*y, h(x,y) = x^3
    - y.

    I need codes like these:
    .
    .
    (Definitions of f, g, h)
    .
    .
    xrange -2 2
    yrange -2 2
    new test 256 256
    list v 0
    fill test 'f(g(x,y),h(x,y))'
    box
    axis
    cont v test

    Thanks in advance.

     
  • Alexey Balakin

    Alexey Balakin - 2011-06-24

    You can use "define" command:

    define $1 (2*x+3*y) # for g
    define $2 (x^3-y) # for h
    fill test '$1^2+$2^3-$1*$2'
    
     
  • Nobody/Anonymous

    Hi abalakin,

    It works fine. Thanks a lot!

    I've got another question. Sorry for the hassle!
    How to define step(x,y) = f(x,y)>0 ? 1:0 in MGL?

     
  • Alexey Balakin

    Alexey Balakin - 2011-06-28

    Just use 'x>0' for step(x). In yours case it will be 'f(x,y)>0'. Note, that
    priority of '>' operator is one of lowest. So, use '(x>0)' inside other
    expressions.

     
  • Nobody/Anonymous

    Hi abalakin,

    Thank you and that's very kind of you!
    Now I can make a clean transparent image with the use of '>' or '<' operators.

     
  • Alexey Balakin

    Alexey Balakin - 2011-06-30

    Don't understand the question completely. There are several ways to make
    figure transparent manually:

    1. You can use plots designed for it (like SurfA(), Surf3A(), Cloud(), TileS() and so on).
    2. You can cut off a region of plot (see SetCut(), SetCutBox(), CutOff())
    3. You can NAN as value of a data cell. Points with NAN will not be plotted.

    I think you mean last case?! You can just divide by zero in formula to produce
    NAN -- for example, try "sin(2pix)/(x^2+y^2>0.1)" or
    "sin(2pix)/(x^2+y^2>0.1)/(x^2+y^2<0.5)"

     
  • Alexey Balakin

    Alexey Balakin - 2011-06-30

    There is also one more way -- draw solid contours using ContF() or ContD().
    Try for example

    new a 20 20: fill a 'x^2+y^2'
    contf [0.1,0.5] a 'r'
    
     
  • Nobody/Anonymous

    Hi abalakin,

    Thank you for your kind support!
    Drawing solid contours using ContD() is a good way. I will try to make use of
    it.

    My original codes are:

    setsize 1280 1280
    plotfactor 1.0
    xrange -1.5 1.5
    yrange -4.0 -1.0
    zrange -2000 2000
    new fun 2560 2560
    fill fun '???' # ??? is the formulas for fun(x,y).
    light off
    surf fun 'rc|'

    And this is the (resized) output image:

    Use GIMP to select the unwanted red-colored regions and fill them with cyan.
    The problem is that the result image is not clean!

    It spent me some time to clean up the image.

    Below are the codes that I used to make images transparent:

    setsize 1280 1280
    plotfactor 1.0
    xrange -1.5 1.5
    yrange -4.0 -1.0
    zrange 0.1 1.0
    new fun 2560 2560
    fill fun '??? < 0.0' # ??? is the formulas for fun(x,y).
    light off
    surf fun 'wr|'

     
  • Alexey Balakin

    Alexey Balakin - 2011-07-01

    With contours you can seve the image into SVG/EPS and edit it as vector figure
    (for example, in Inksape).

     

Log in to post a comment.