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.Fri, 21 Jul 2017 23:45:30 +0200How to plot a complicated function in Sage Mathhttps://ask.sagemath.org/question/38159/how-to-plot-a-complicated-function-in-sage-math/I apologize in advance for my lack of knowledge and understanding of sage.
In principle what I want to achieve is the visualization of this function:
$$ g \mapsto \left|x - \lfloor{x}\rfloor - \frac{1}{2} \right| $$
$$f(x) := \sum_{j=0}^\infty 2^{-j}g(2^jx)$$
Though I am having trouble finding out how to do this. In the documentation I did not find any easy way to handle infinite series.
I am sure this would be very helpful to many that struggle with a math problem and need to see it to believe it. A conventional plotting program will not work here, hence I searched for a better tool and found Sage Math.
Is it possible in sage? Do you have any TLDR material that I could look into?
Thank you for your help.
Sat, 01 Jul 2017 20:04:42 +0200https://ask.sagemath.org/question/38159/how-to-plot-a-complicated-function-in-sage-math/Comment by roberto for <p>I apologize in advance for my lack of knowledge and understanding of sage.
In principle what I want to achieve is the visualization of this function:</p>
<p>$$ g \mapsto \left|x - \lfloor{x}\rfloor - \frac{1}{2} \right| $$
$$f(x) := \sum_{j=0}^\infty 2^{-j}g(2^jx)$$</p>
<p>Though I am having trouble finding out how to do this. In the documentation I did not find any easy way to handle infinite series.</p>
<p>I am sure this would be very helpful to many that struggle with a math problem and need to see it to believe it. A conventional plotting program will not work here, hence I searched for a better tool and found Sage Math.
Is it possible in sage? Do you have any TLDR material that I could look into? </p>
<p>Thank you for your help.</p>
https://ask.sagemath.org/question/38159/how-to-plot-a-complicated-function-in-sage-math/?comment=38160#post-id-38160So do you want to plot a function which is 1 for x>=0 and +Infinity for x<0?Sun, 02 Jul 2017 00:51:28 +0200https://ask.sagemath.org/question/38159/how-to-plot-a-complicated-function-in-sage-math/?comment=38160#post-id-38160Comment by roberto for <p>I apologize in advance for my lack of knowledge and understanding of sage.
In principle what I want to achieve is the visualization of this function:</p>
<p>$$ g \mapsto \left|x - \lfloor{x}\rfloor - \frac{1}{2} \right| $$
$$f(x) := \sum_{j=0}^\infty 2^{-j}g(2^jx)$$</p>
<p>Though I am having trouble finding out how to do this. In the documentation I did not find any easy way to handle infinite series.</p>
<p>I am sure this would be very helpful to many that struggle with a math problem and need to see it to believe it. A conventional plotting program will not work here, hence I searched for a better tool and found Sage Math.
Is it possible in sage? Do you have any TLDR material that I could look into? </p>
<p>Thank you for your help.</p>
https://ask.sagemath.org/question/38159/how-to-plot-a-complicated-function-in-sage-math/?comment=38353#post-id-38353My bad I thought it was abs(x) instead of floor(x)Fri, 21 Jul 2017 23:45:30 +0200https://ask.sagemath.org/question/38159/how-to-plot-a-complicated-function-in-sage-math/?comment=38353#post-id-38353Answer by B r u n o for <p>I apologize in advance for my lack of knowledge and understanding of sage.
In principle what I want to achieve is the visualization of this function:</p>
<p>$$ g \mapsto \left|x - \lfloor{x}\rfloor - \frac{1}{2} \right| $$
$$f(x) := \sum_{j=0}^\infty 2^{-j}g(2^jx)$$</p>
<p>Though I am having trouble finding out how to do this. In the documentation I did not find any easy way to handle infinite series.</p>
<p>I am sure this would be very helpful to many that struggle with a math problem and need to see it to believe it. A conventional plotting program will not work here, hence I searched for a better tool and found Sage Math.
Is it possible in sage? Do you have any TLDR material that I could look into? </p>
<p>Thank you for your help.</p>
https://ask.sagemath.org/question/38159/how-to-plot-a-complicated-function-in-sage-math/?answer=38166#post-id-38166You can proceed as follows, where $N$ is given to serve as an approximation of $\infty$.
sage: g(x) = abs(x - floor(x) - 1/2)
sage: def f(x, N): return sum(g(2^j*x)/2^j for j in range(N+1))
sage: N = 100 # for instance...
sage: plot(f(x, N), x, -1, 1)
![Resulting plot](/upfiles/14990966539260471.png)
**Note.** For this approach to make sense, you need to show that that the partial sums converge fast, which is the case since $g(x) \le 1/2$ for all $x$.Mon, 03 Jul 2017 17:44:57 +0200https://ask.sagemath.org/question/38159/how-to-plot-a-complicated-function-in-sage-math/?answer=38166#post-id-38166