question about plot3d



To be more precise, plot2d/3d evaluates all its arguments.  The *value *of
the first argument should be an expression or a function (name or anonymous
function).

Thus:

      foo: sin(x)$
      plot2d(foo,[x,0,1])  => plots sin(x)
      foo: 'sin$
      plot2d(foo,[x,0,1]) => plots sin(x)
      foo: lambda([x],sin(x))$
      plot2d(foo,[x,0,1]) => plots sin(x)

In your case, you can write

        plot2d(f, ...)  as Jaime suggests

or equally well:

        plot2d( '( f(x,y) ), ...)

Alternatively, you can define f to return a conditional expression:

      f(x,y):= if (y< -sqrt(1-x^2) or  y>sqrt(1-x^2)) then false else
sin(x*y))

in which case both f(x,y)  (which returns the expression " if (y< -sqrt...)
... " ) and '( f(x,y) ) (which returns the expression "f(x,y)") will work.

More simply, you can define f as an expression directly:

      f:  if (y< -sqrt(1-x^2) or  y>sqrt(1-x^2)) then false else sin(x*y))

Hope this helps you understand Maxima's evaluation system.

                 -s


On Sat, Nov 17, 2012 at 8:32 AM, Jaime Villate <villate at fe.up.pt> wrote:

> On 11/17/2012 09:15 AM, Dmitry Shkirmanov wrote:
>
>> f(x,y):=block([],
>> if (y<-sqrt(1-x^2) or  y>sqrt(1-x^2)) then return(false),
>> sin(x*y));
>> plot3d(f(x,y),[x,-1,1],[y,-1,**1])$
>>
>> returns graph of sin(x*y) on the whole square [x,-1,1],[y,-1,1].
>> It looks like a bug. Am i wrong?
>>
> It is not a bug but a feature. plot3d expects either an expression or the
> name of a function.
>
> By introducing return, your function f no longer produces an expression.
> Thus, when you write f(x,y) inside plot3d, the program is expecting an
> expression so it tries to get one, even before substituting values for x
> and y; the expression passed is sin(x*y) and your command becomes
> equivalent to having written plot3d(sin(x*y),[x,-1,1],[y,-**1,1])
>
> When you are dealing with a function, as the one above, and not with
> expression, use only the name of the function; the following will work as
> you expected:
>
> plot3d(f,[x,-1,1],[y,-1,1])$
>
> Regards,
> Jaime
>
>
> ______________________________**_________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/**mailman/listinfo/maxima<http://www.math.utexas.edu/mailman/listinfo/maxima>;
>