ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 08 Oct 2013 00:38:03 -0500Can I express a function as a series of another set of functionshttp://ask.sagemath.org/question/10596/can-i-express-a-function-as-a-series-of-another-set-of-functions/Let me give an example
Suppose I want to expand $\cos(x)^{4}$ as in a series of functions $C_{k}=(1/2-\cos(kx))$.
That is $\cos(4x)=k_0 C_0+k_1 C_1 + k_2 C_2 \cdots$ and I am looking for coefficients $k$
Now, I can use trig_reduce() to express $\cos(x)^{4}$ as a sum $\cos(kx)$, but how do I get get $\cos(x)^4$ in terms of $C_{k}$. Mon, 07 Oct 2013 19:01:30 -0500http://ask.sagemath.org/question/10596/can-i-express-a-function-as-a-series-of-another-set-of-functions/Answer by tmonteil for <p>Let me give an example</p>
<p>Suppose I want to expand $\cos(x)^{4}$ as in a series of functions $C_{k}=(1/2-\cos(kx))$.
That is $\cos(4x)=k_0 C_0+k_1 C_1 + k_2 C_2 \cdots$ and I am looking for coefficients $k$</p>
<p>Now, I can use trig_reduce() to express $\cos(x)^{4}$ as a sum $\cos(kx)$, but how do I get get $\cos(x)^4$ in terms of $C_{k}$. </p>
http://ask.sagemath.org/question/10596/can-i-express-a-function-as-a-series-of-another-set-of-functions/?answer=15525#post-id-15525To get the coefficients of `cos(x)^4` in terms of the family `cos(k*x)`, you can try:
sage: f = cos(x)^4
sage: g = f.trig_reduce() ; g
1/2*cos(2*x) + 1/8*cos(4*x) + 3/8
sage: C = [g.coefficient(cos(k*x)) for k in range(5)] ; C
[0, 0, 1/2, 0, 1/8]
But as you can see, Maxima gives a wrong answer since it is not able to understand that 3/8 is the coefficients in `cos(0*x)`, so you have to recover it:
sage: h = sum([C[k]*cos(k*x) for k in range(len(C))]) ; h
1/2*cos(2*x) + 1/8*cos(4*x)
sage: C[0] = g-h ; C
[3/8, 0, 1/2, 0, 1/8]
On the way back, can build the sum and then simplify the sum as follows:
sage: C = [3/8, 0, 1/2, 0, 1/8]
sage: sum([C[k]*cos(k*x) for k in range(len(C))]).trig_simplify()
cos(x)^4
So we can go back and forth from `cos(x)^4` to its coefficients in the family `(cos(k*x))` automatically.
If you want to do the same for the family `(1/2 - cos(k*x))`, this is just linear algebra, going from one basis to another. For this, you just have to build the matrix `M` that express the family `(1/2 - cos(k*x))` in terms of the family `(cos(k*x))` (you should be careful of the Maxima error as well so that the coefficient 1/2 will not disapear) and apply the inverse of this matrix to C (viewed as a vector), and you get:
sage: D
(-11/8, 0, -1/2, 0, -1/8)
sage: sum([D[k]*(1/2-cos(k*x)) for k in range(len(D))]).trig_simplify()
cos(x)^4
Tue, 08 Oct 2013 00:38:03 -0500http://ask.sagemath.org/question/10596/can-i-express-a-function-as-a-series-of-another-set-of-functions/?answer=15525#post-id-15525