Skip to content

Commit f94c8ca

Browse files
committed
Compute weights for quadrature
Add function chebyshev_quadrature that computes the nodes and weights for qauss-chebyshev quadrature with weighting functions of the first and second kind.
1 parent f4004fe commit f94c8ca

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "ChebyshevApprox"
22
uuid = "17a596ad-87cd-578c-9b6d-01108c31dc04"
33
authors = ["Richard Dennis <richard.dennis@glasgow.ac.uk>"]
4-
version = "0.1.12"
4+
version = "0.1.13"
55

66
[deps]
77
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"

src/ChebyshevApprox.jl

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ include("chebyshev_nodes.jl")
88
include("chebyshev_extrema.jl")
99
include("chebyshev_extended.jl")
1010
include("vertesi_nodes.jl")
11+
include("chebyshev_quadrature.jl")
1112
include("normalize_node.jl")
1213
include("chebyshev_polynomial.jl")
1314
include("chebyshev_weights.jl")
@@ -25,6 +26,7 @@ export chebyshev_nodes,
2526
chebyshev_extrema,
2627
chebyshev_extended,
2728
vertesi_nodes,
29+
chebyshev_quadrature,
2830
chebyshev_polynomial,
2931
chebyshev_weights,
3032
chebyshev_weights_extrema,

src/chebyshev_quadrature.jl

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
function chebyshev_quadrature(node_type::Function,n::S,domain = [1.0,-1.0]) where {S <: Integer}
2+
3+
if n <= 0
4+
5+
error("The number of nodes must be positive.")
6+
7+
end
8+
9+
nodes = zeros(n)
10+
weights = zeros(n)
11+
12+
if node_type == chebyshev_nodes # weighting function is (1.0 .- nodes.^2).^(-1/2) -- (first kind)
13+
14+
for i = 1:n
15+
nodes[i] = (domain[1]+domain[2])/2.0 - cos((i-0.5)*pi/n)*(domain[1]-domain[2])/2.0
16+
weights[i] = pi/n
17+
end
18+
19+
return nodes, weights
20+
21+
elseif node_type == chebyshev_extrema # weighting function is (1.0 .- nodes.^2).^(1/2) -- (second kind)
22+
23+
for i = 1:n
24+
nodes[i] = (domain[1]+domain[2])/2.0 - cos((i-1)*pi/(n-1))*(domain[1]-domain[2])/2.0
25+
weights[i] = (pi/(n-1))*sin(((i-1)/(n-1))*pi)^2
26+
end
27+
28+
return nodes, weights
29+
30+
else
31+
32+
error("This node type is not supported")
33+
34+
end
35+
36+
end
37+

0 commit comments

Comments
 (0)