Search code examples
scilab

Troubles with singularity of log when trying to plot a function in Scilab


I'm trying to plot the function : log(y-x^2).

I've tried some things like :

    clf()
    x=-10:0.001:10
    y=x
    y(find(y <= x.^2)) = %nan
    plot3d(x, y, log(y-x.^2))

but it doesn't work.

I've also searched on how to define a set but found no real results.

If you knew either what i do wrong or how i can define a set with a function it would help me a lot.

Thanks.


Solution

  • If I get your intention right, you want to plot a "surface". To do this (in one way), you need to define an evenly spaced grid. The easiest way is with ndgrid. Then you calculate the "surface" points above this grid. Try the following code:

    clf()
    x=-10:0.5:10;
    y=x;
    [xx,yy]=ndgrid(x,y);  //grid coordinates
    M=yy-xx.^2;   //the surface points
    M(find(M==0))=%nan;   //kill 0s to avoid log singularity
    plot3d(x,y,log(M));
    

    Another possible way to avoid the singularity, is to define x such way, that M never becomes zero, e.g.:

    x=-10:0.51:10;
    

    This way you won't have "holes" in your surface.