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.Mon, 17 Jun 2024 08:17:32 +0200Plot real to complex functionhttps://ask.sagemath.org/question/77872/plot-real-to-complex-function/I have a function that has real domain and a complex co-domain. I want to plot the real and imaginary parts together, like this: imgur.com/a/yb7g5Ce
The code that I used to generate that plot (`plot(real(F(x)),(-2,2)) + plot(imag(F(x)),(-2,2),color="red")`) works, but I think every value is being calculated two times, discarding either the real or the imaginary part. Is there any way to get this effect more efficiently, without doing useless calculations?Sun, 16 Jun 2024 18:23:19 +0200https://ask.sagemath.org/question/77872/plot-real-to-complex-function/Answer by Emmanuel Charpentier for <p>I have a function that has real domain and a complex co-domain. I want to plot the real and imaginary parts together, like this: imgur.com/a/yb7g5Ce</p>
<p>The code that I used to generate that plot (<code>plot(real(F(x)),(-2,2)) + plot(imag(F(x)),(-2,2),color="red")</code>) works, but I think every value is being calculated two times, discarding either the real or the imaginary part. Is there any way to get this effect more efficiently, without doing useless calculations?</p>
https://ask.sagemath.org/question/77872/plot-real-to-complex-function/?answer=77875#post-id-77875From [the Python documentation](https://docs.python.org/3/library/functools.html) :
`@functools.cache(user_function)`
Simple lightweight unbounded function cache. Sometimes called “memoize”.
Returns the same as `lru_cache(maxsize=None)`, creating a thin wrapper around a dictionary lookup for the function arguments. Because it never needs to evict old values, this is smaller and faster than `lru_cache()` with a size limit.
HTH,Mon, 17 Jun 2024 08:17:32 +0200https://ask.sagemath.org/question/77872/plot-real-to-complex-function/?answer=77875#post-id-77875