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, 13 Mar 2020 16:51:30 -0500Problem with plotting "lambda" functionshttps://ask.sagemath.org/question/50229/problem-with-plotting-lambda-functions/ The following code returns AttributeError
F(x, k) = gamma_inc_lower(k/2, x/2) / gamma(k/2)
plot((lambda k: find_root(F(x, k) - 1/2, 0, 100)), (k, 1, 10))
I think there is some problem with coercion of Python function to Sage function, but I have no idea how to solve it in an elegant way.
Any solution, please?Fri, 13 Mar 2020 12:20:28 -0500https://ask.sagemath.org/question/50229/problem-with-plotting-lambda-functions/Answer by rburing for <p>The following code returns AttributeError </p>
<pre><code>F(x, k) = gamma_inc_lower(k/2, x/2) / gamma(k/2)
plot((lambda k: find_root(F(x, k) - 1/2, 0, 100)), (k, 1, 10))
</code></pre>
<p>I think there is some problem with coercion of Python function to Sage function, but I have no idea how to solve it in an elegant way. </p>
<p>Any solution, please?</p>
https://ask.sagemath.org/question/50229/problem-with-plotting-lambda-functions/?answer=50231#post-id-50231You need more lambdas! When you're doing numerical stuff you usually want to work with Python functions rather than symbolic expressions, like so:
plot((lambda k: find_root(lambda x: F(x, k) - 1/2, 0, 100)), (k, 1, 10))
This ensures that `x` and `k` are numbers when you write `F(x,k)`, so it will evaluate to a number (as desired).Fri, 13 Mar 2020 16:51:30 -0500https://ask.sagemath.org/question/50229/problem-with-plotting-lambda-functions/?answer=50231#post-id-50231