ASKSAGE: Sage Q&A Forum - Individual question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Fri, 28 Dec 2018 13:20:09 -0600Why doesn't assume(x, 'real') exclude complex values when using plot(x^(1/3)) over a negative domain?https://ask.sagemath.org/question/44798/why-doesnt-assumex-real-exclude-complex-values-when-using-plotx13-over-a-negative-domain/ Running the following commands:
assume(x,'real')
plot(x^(1/3), -5, 5)
produces the following error:
verbose 0 (3630: plot.py, generate_plot_points) WARNING: When plotting, failed to evaluate function at 100 points.
verbose 0 (3630: plot.py, generate_plot_points) Last error message: 'negative number cannot be raised to a fractional power'
Shouldn't the assume command take care of this?
Thanks.
Thu, 27 Dec 2018 21:04:18 -0600https://ask.sagemath.org/question/44798/why-doesnt-assumex-real-exclude-complex-values-when-using-plotx13-over-a-negative-domain/Answer by slelievre for <p>Running the following commands:</p>
<p>assume(x,'real')
plot(x^(1/3), -5, 5)</p>
<p>produces the following error:
verbose 0 (3630: plot.py, generate_plot_points) WARNING: When plotting, failed to evaluate function at 100 points.
verbose 0 (3630: plot.py, generate_plot_points) Last error message: 'negative number cannot be raised to a fractional power'</p>
<p>Shouldn't the assume command take care of this?</p>
<p>Thanks.</p>
https://ask.sagemath.org/question/44798/why-doesnt-assumex-real-exclude-complex-values-when-using-plotx13-over-a-negative-domain/?answer=44800#post-id-44800The following workaround can help:
sage: plot(lambda x: sgn(x)*(x*sgn(x))^(1/3), (-5, 5))
One can also use an implicit plot:
sage: implicit_plot(y^3 == x, (x, -5, 5), (y, -2, 2))Fri, 28 Dec 2018 13:20:09 -0600https://ask.sagemath.org/question/44798/why-doesnt-assumex-real-exclude-complex-values-when-using-plotx13-over-a-negative-domain/?answer=44800#post-id-44800