Ask Your Question
1

Unable to create a contour_plot of a system of inequalities

asked 2016-07-16 14:30:45 -0600

this post is marked as community wiki

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 flag offensive close merge delete

Comments

Thanks for reporting !

tmonteil gravatar imagetmonteil ( 2016-07-18 06:08:27 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2016-07-17 20:49:32 -0600

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.

edit flag offensive delete link more

Comments

Thanks for tracking !

tmonteil gravatar imagetmonteil ( 2016-07-18 06:08:58 -0600 )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 :(

petkus gravatar imagepetkus ( 2016-07-20 01:15:28 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2016-07-16 14:30:45 -0600

Seen: 65 times

Last updated: Jul 17 '16