Ask Your Question

Revision history [back]

Vector field plot

I am encountering strange behavior when plotting a vectorfield. My example is much more complicated, but here is a simplification which still behaves badly for me:

def g(x):
    if x<0:
        return -1
    else:
        return 1

x,y = var('x,y')
plot_vector_field((g(x),0), (x,-1,1),(y,-1,1))

The plotted result shows all vectors plotted as (1,0), which is not right. I guess I'm not allowed to use bare python if/else in the definition of g? Is there some different way to call plot_vector_field so that this will work?

Vector field plot

I am encountering strange behavior when plotting a vectorfield. My example is much more complicated, but here is a simplification which still behaves badly for me:

def g(x):
    if x<0:
        return -1
    else:
        return 1

x,y = var('x,y')
plot_vector_field((g(x),0), (x,-1,1),(y,-1,1))

The plotted result shows all vectors plotted as (1,0), which is not right. I guess I'm not allowed to use bare python if/else in the definition of g? Is there some different way to call plot_vector_field so that this will work?