# Revision history [back]

You 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


You To get the coefficients in cos(k*x), you can:

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 is not able to understand that 3/8 is the oefficients 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
sage: C = 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.

To get the coefficients in of cos(x)^4 in terms of the family cos(k*x), you can: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 oefficients 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
sage: C = 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.

To 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
sage: C = 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. 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.

another. For this, you just have to write the matrix that express the family (1/2 - cos(k*x)) in terms of the family (cos(k*x)) and take its inverse.

To 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
sage: C = 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 write build the matrix that express the family (1/2 - cos(k*x)) in terms of the family (cos(k*x)) and take apply its inverse.

inverse to F (viewed as a vector).

To 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 = 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 that express the family (1/2 - cos(k*x)) in terms of the family (cos(k*x)) and apply its inverse to F (viewed as a vector).

To 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 = 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 that express the family (1/2 - cos(k*x)) in terms of the family (cos(k*x)) and apply its the inverse to F of this matrix to C (viewed as a vector).

To 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 = 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).

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