File tree Expand file tree Collapse file tree 2 files changed +29
-13
lines changed Expand file tree Collapse file tree 2 files changed +29
-13
lines changed Original file line number Diff line number Diff line change @@ -116,19 +116,21 @@ end
116
116
# end
117
117
118
118
# #
119
- # function companion(p::ChebyshevT{T}) where T
120
- # d = length(p) - 1
121
- # d < 1 && error("Series must have degree greater than 1")
122
- # d == 1 && return diagm(0 => [-p[0] / p[1]])
123
- # R = eltype(one(T) / p.coeffs[end])
124
-
125
- # comp = diagm(-1 => ones(d - 1),
126
- # 1 => ones(d - 1))
127
- # comp[2, 1] = 2
128
- # monics = p.coeffs ./ p.coeffs[end]
129
- # comp[:, end] .= -monics[1:d]
130
- # return R.(comp ./ 2)
131
- # end
119
+ function companion (p:: ChebyshevT{T} ) where T
120
+ d = length (p) - 1
121
+ d < 1 && error (" Series must have degree greater than 1" )
122
+ d == 1 && return diagm (0 => [- p[0 ] / p[1 ]])
123
+ R = eltype (one (T) / one (T))
124
+
125
+ scl = append! ([1.0 ], √ 5 .* ones (d - 1 ))
126
+
127
+ diag = append! ([√ 5 ], 0.5 .* ones (d - 2 ))
128
+ comp = diagm (- 1 => diag,
129
+ 1 => diag)
130
+ monics = p. coeffs ./ p. coeffs[end ]
131
+ comp[:, end ] .- = monics[1 : d] .* scl ./ scl[end ]
132
+ return R .(comp ./ 2 )
133
+ end
132
134
133
135
function Base.:+ (p1:: ChebyshevT , p2:: ChebyshevT )
134
136
p1. var != p2. var && error (" Polynomials must have same variable" )
Original file line number Diff line number Diff line change 71
71
72
72
end
73
73
74
+ @testset " Companion" begin
75
+ c_null = ChebyshevT (Int[])
76
+ c_1 = ChebyshevT ([1 ])
77
+ @test_throws ErrorException companion (c_null)
78
+ @test_throws ErrorException companion (c_1)
79
+ for i in 1 : 5
80
+ coef = push! (zeros (i), 1 )
81
+ c = ChebyshevT (coef)
82
+ @test size (companion (c)) == (i, i)
83
+ end
84
+ c = ChebyshevT ([1 , 2 ])
85
+ @test companion (c)[1 , 1 ] == - 0.5
86
+ end
87
+
74
88
@testset " Arithmetic $i , $j " for i in 1 : 5 , j in 1 : 5
75
89
# multiplication
76
90
target = zeros (i + j + 1 )
You can’t perform that action at this time.
0 commit comments