TypeError: unsupported operand parent(s) for *: 'Integer Ring' and '<class 'NoneType'>'

asked 2021-02-11 04:39:34 +0100

breaks240 gravatar image

updated 2021-02-11 07:02:14 +0100

slelievre gravatar image

I keep getting an error when wanting to plot a slope field x' = -x + 80 - 40*sign(t-6)

My code looks like:

var('t,x')

def sign(t):
    if t > 0:
        return 1
    if t == 0:
        return 0
    if t < 0:
        return -1

plot_slope_field(-x+80-40*sign(t-6), (t, 0, 5), (y,0,5))

And the ERROR is:

TypeError                                 Traceback (most recent call last)

<ipython-input-1-5af90de417a8> in <module>
      9 def f(t):
     10     sgn(t-Integer(6))
---> 11 plot_slope_field(-x+Integer(80)-Integer(40)*f(t),(t,Integer(0),Integer(5)),(x,Integer(0),Integer(5)))

/home/sc_serv/sage/local/lib/python3.8/site-packages/sage/rings/integer.pyx in sage.rings.integer.Integer.__mul__ (build/cythonized/sage/rings/integer.c:14016)()
   1980             return y
   1981 
-> 1982         return coercion_model.bin_op(left, right, operator.mul)
   1983 
   1984     cpdef _mul_(self, right):

/home/sc_serv/sage/local/lib/python3.8/site-packages/sage/structure/coerce.pyx in sage.structure.coerce.CoercionModel.bin_op (build/cythonized/sage/structure/coerce.c:11304)()
   1246         # We should really include the underlying error.
   1247         # This causes so much headache.
-> 1248         raise bin_op_exception(op, x, y)
   1249 
   1250     cpdef canonical_coercion(self, x, y):

TypeError: unsupported operand parent(s) for *: 'Integer Ring' and '<class 'NoneType'>'
edit retag flag offensive close merge delete

Comments

1
  • There is no need to define your sign fonctin :the built-in sgn function is enough.

  • Your function is an expression of x and t, but your plot is a function of y and t.

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2021-02-11 09:15:20 +0100 )edit