Ask Your Question

leingang's profile - activity

2018-10-02 18:38:27 +0100 commented answer Graphing max function - unexpected behavior

Very informative, thank you.

2018-10-02 18:37:44 +0100 received badge  Scholar (source)
2018-10-02 18:37:43 +0100 received badge  Supporter (source)
2018-10-01 17:04:33 +0100 received badge  Self-Learner (source)
2018-10-01 17:04:33 +0100 received badge  Teacher (source)
2018-10-01 15:27:55 +0100 received badge  Student (source)
2018-10-01 15:20:58 +0100 answered a question Graphing max function - unexpected behavior

Using one of the related questions that came up after I submitted, I think I found the correct way to get the expected plot:

contour_plot(f,(x,-3,3),(y,-3,3))

However, this still doesn't work as expected:

contour_plot(max(abs(x),abs(y)),(x,-3,3),(y,-3,3))
2018-10-01 15:20:58 +0100 asked a question Graphing max function - unexpected behavior

My minimal working example is:

(x,y) = var('x y')
def f(x,y):
    return max(abs(x),abs(y))

table([[f(x,y) for y in range(-3,4)] for x in range(-3,4)])

The output is this table:

  3   3   3   3   3   3   3
  3   2   2   2   2   2   3
  3   2   1   1   1   2   3
  3   2   1   0   1   2   3
  3   2   1   1   1   2   3
  3   2   2   2   2   2   3
  3   3   3   3   3   3   3

That looks like it ought to. But when I try

contour_plot(f(x,y),(x,-3,3),(y,-3,3))

I get something that looks a lot different. It seems I don't have enough karma to upload the image, but its looks more like the one that would be associated to this table:

table([[f(0,y) for y in range(-3,4)] for x in range(-3,4)])

  3   2   1   0   1   2   3
  3   2   1   0   1   2   3
  3   2   1   0   1   2   3
  3   2   1   0   1   2   3
  3   2   1   0   1   2   3
  3   2   1   0   1   2   3
  3   2   1   0   1   2   3

I have the issue isolated in a Sage worksheet on CoCalc. I don't have enough karma to include a link, either.