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, 22 Oct 2019 18:04:34 +0200abs and plot problemhttps://ask.sagemath.org/question/48469/abs-and-plot-problem/Hi there.
Using Cocalc, I am encountering problems trying to plot some functions.
The following simple example shows how I am able to plot the modulus of a simple function using my own modulus function, but how it fails using abs(). Which is really weird.
_ = var('a,x')
MODULUS(x) = sqrt(real(x)^2 + imag(x)^2)
Hmod = MODULUS(a*x + i*x^2)
Habs = abs(a*x + i*x^2)
plot([Hmod(a=n) for n in [1..5]], (x,0, 2))
plot([Habs(a=n) for n in [1..5]], (x,0, 2))
Hmod can be plotted, while Habs will return "TypeError: unable to coerce to a real number".
On the other hand the following works:
plot(Habs(a=1), (x,0, 2))
So it works without list comprehension and with my MODULUS function... Don't know what to think of that.
Anyone can help on that? I have seriously more complicated cases that I seem to be unable to plot because of this very problem.
Thanks a lot.Tue, 22 Oct 2019 16:33:38 +0200https://ask.sagemath.org/question/48469/abs-and-plot-problem/Comment by FrédéricC for <p>Hi there.
Using Cocalc, I am encountering problems trying to plot some functions.
The following simple example shows how I am able to plot the modulus of a simple function using my own modulus function, but how it fails using abs(). Which is really weird.</p>
<p>_ = var('a,x')</p>
<p>MODULUS(x) = sqrt(real(x)^2 + imag(x)^2)</p>
<p>Hmod = MODULUS(a<em>x + i</em>x^2)</p>
<p>Habs = abs(a<em>x + i</em>x^2)</p>
<p>plot([Hmod(a=n) for n in [1..5]], (x,0, 2))</p>
<p>plot([Habs(a=n) for n in [1..5]], (x,0, 2))</p>
<p>Hmod can be plotted, while Habs will return "TypeError: unable to coerce to a real number". </p>
<p>On the other hand the following works:</p>
<p>plot(Habs(a=1), (x,0, 2))</p>
<p>So it works without list comprehension and with my MODULUS function... Don't know what to think of that.</p>
<p>Anyone can help on that? I have seriously more complicated cases that I seem to be unable to plot because of this very problem.
Thanks a lot.</p>
https://ask.sagemath.org/question/48469/abs-and-plot-problem/?comment=48470#post-id-48470Strange. This works
sage: plot([Habs(a=0) for n in range(1,3)],(x,0,2))
Launched png viewer for Graphics object consisting of 2 graphics primitives
but this fails
sage: plot([Habs(a=1) for n in range(1,3)],(x,0,2))
BOOMTue, 22 Oct 2019 17:43:17 +0200https://ask.sagemath.org/question/48469/abs-and-plot-problem/?comment=48470#post-id-48470Comment by cedrik0s for <p>Hi there.
Using Cocalc, I am encountering problems trying to plot some functions.
The following simple example shows how I am able to plot the modulus of a simple function using my own modulus function, but how it fails using abs(). Which is really weird.</p>
<p>_ = var('a,x')</p>
<p>MODULUS(x) = sqrt(real(x)^2 + imag(x)^2)</p>
<p>Hmod = MODULUS(a<em>x + i</em>x^2)</p>
<p>Habs = abs(a<em>x + i</em>x^2)</p>
<p>plot([Hmod(a=n) for n in [1..5]], (x,0, 2))</p>
<p>plot([Habs(a=n) for n in [1..5]], (x,0, 2))</p>
<p>Hmod can be plotted, while Habs will return "TypeError: unable to coerce to a real number". </p>
<p>On the other hand the following works:</p>
<p>plot(Habs(a=1), (x,0, 2))</p>
<p>So it works without list comprehension and with my MODULUS function... Don't know what to think of that.</p>
<p>Anyone can help on that? I have seriously more complicated cases that I seem to be unable to plot because of this very problem.
Thanks a lot.</p>
https://ask.sagemath.org/question/48469/abs-and-plot-problem/?comment=48471#post-id-48471@FredericC: yes that's really weird, and it actually looks a bit random. I have had your second line work some time and others not... but I can't figure what to do to make it work (or not) systematically...Tue, 22 Oct 2019 18:04:34 +0200https://ask.sagemath.org/question/48469/abs-and-plot-problem/?comment=48471#post-id-48471