# Unable to create a contour_plot of a system of inequalities

This post is a wiki. Anyone with karma >750 is welcome to improve it.

I am trying to plot a system of inequalities, dependent on a matrix H. Here is my function I am planning to contour_plot:

def reg(x, y):
f1 = H[0,0] * H[0,0] * x + H[1,0] * H[1,0] * y
f2 = H[0,0] * H[0,1] * x + H[1,0] * H[1,1] * y
f3 = H[0,1] * H[0,1] * x + H[1,1] * H[1,1] * y
if f1 < 0 or f2 < 0 or f3 < 0:
return 0
else:
return 1


I then have H be

> H
>  [2.220446049250313e-16   -0.9999999999999998]
>  [  -0.9999999999999998 2.220446049250313e-16]


However

contour_plot(reg, (x,-Integer(5),Integer(5)), (y,-Integer(5),Integer(5)))


yields an error. It says

zero-size array to reduction operation minimum which has no identity


The strange part is that when

> H
>  [-1 0]
>  [ 0 1]


the same contour_plot yields exactly what I want without any errors
Help would be much appreciated, I have just picked up SAGE this week and have much to learn

edit retag close merge delete

Thanks for reporting !

( 2016-07-18 13:08:27 +0200 )edit

Sort by ยป oldest newest most voted

The cause of the error message is that your function reg is returning all zero values for the first matrix H. Somewhere down the line Sage tries to take an inverse of zero and that returns an error. I've created a ticket to report this problem.

One workaround for you is to have your function return a small nonzero value rather than exactly zero to avoid the error. Here's a live example.

more

Thanks for tracking !

( 2016-07-18 13:08:58 +0200 )edit

Thanks! It turns out the problem wasn't with what the function returned but with the inequalities. I set f1 < -1e-3, f2 < -1e-3, f3 < -1e-3 and it works how I wanted. This is a very strange bug that really makes sage a black box to me :(

( 2016-07-20 08:15:28 +0200 )edit