ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 24 Nov 2020 02:35:26 +0100How to define y=constant function to plothttps://ask.sagemath.org/question/54377/how-to-define-yconstant-function-to-plot/ Hi!
I'm newbe with SageMath and i would like to make an y=constant function to plot but i don't find a way to do it.
I can do x=constant functions plot easily:
c=1
plot(c, (x,-2,2))
But how can I do y=constant if it is possible!?
Thanks!
Tue, 24 Nov 2020 00:33:15 +0100https://ask.sagemath.org/question/54377/how-to-define-yconstant-function-to-plot/Answer by Emmanuel Charpentier for <p>Hi!</p>
<p>I'm newbe with SageMath and i would like to make an y=constant function to plot but i don't find a way to do it.</p>
<p>I can do x=constant functions plot easily:</p>
<p>c=1
plot(c, (x,-2,2))</p>
<p>But how can I do y=constant if it is possible!?</p>
<p>Thanks!</p>
https://ask.sagemath.org/question/54377/how-to-define-yconstant-function-to-plot/?answer=54378#post-id-54378`plot(lambda u:1, (-2, 2))` plots an *horizontal* line where `y` is constant (i. e. $y=1$).
Do you want a *vertical* line, where the same value of `x` of `x` corresponds to (infinitely) many values of `y` ? This by definition *cannot* be the representation of a function of `x`.
You can use a parametric representation of such a vertical line ; for example, `parametric_plot([1,lambda u:u],(0,2))` will plot the vertical segment from `(1,0)` to `(1,2)`.
You can also directly use the primitive `line` : `line([(1,0),(1,2)])` will get the same result as before.
There are probably other ways, whose search is left to you as an exercise...
Tue, 24 Nov 2020 02:35:26 +0100https://ask.sagemath.org/question/54377/how-to-define-yconstant-function-to-plot/?answer=54378#post-id-54378