Ask Your Question

contour_plot/plot and function arguments

asked 2017-02-09 16:06:46 -0500

anonymous user



I am considering switching from Mathematica to Sage but I am confused on some fundamental matters pertaining Sage. I really appreciate if you could shed some light on the problem .

Let's look at the code in Sage:

f(k1,k2) = k1^2 + k2

this code beautifully draws the contour. Now, what I tried was switching the order of the arguments of f from f(k1,k2) to f(k2,k1):


What I intuitively expected was the switch of the graph. I expected (0,2) to match k2 instead of k1 since it is the first argument of the new function f and (3,5) to k1 instead of k2 (for the same reasoning). However, the graph was identical to that of f(k1,k2). How does Sage choose range arguments to match with f arguments?

I have a similar problem with plot as well:


This code draws the graph, but the function is in z and the range variable is in t. Shouldn't it give an error?! This code is wrong in Mathematica


it should be Plot[f[t],{t,0,5}]. Why doesn't Sage give an error?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2017-02-10 22:23:48 -0500

updated 2017-02-10 22:44:48 -0500

When ranges are given without explicit variables, the plotting routine creates a list of function arguments in alphabetical order of variable names, and the ranges are then assigned in the same order. You can (and probably should) override this automatic behavior by always specifying names: contour_plot(f,(k1,0,2),(k2,3,5)) will then differ from contour_plot(f,(k2,0,2),(k1,3,5)) as expected.

The missing error with plot occurs because the routine sets a flag expect_one_var=True. This is meant to be a convenience that makes plotting a bit easier by suppressing a different error message. Unfortunately it creates the confusion you've noticed.

edit flag offensive delete link more


Thank you very much. I greatly appreciate your answer.

curios_mind gravatar imagecurios_mind ( 2017-02-12 04:22:28 -0500 )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


Asked: 2017-02-09 16:06:46 -0500

Seen: 38 times

Last updated: Feb 10