In [1]:
include("../src/Jacobi.jl")
Out[1]:
In [2]:
#fun(x,k=1) = cos(k*x) + 1
#ifun(x,k=1) = x + sin(k*x) / k
fun(x) = cos(x)
ifun(x) = -x.*sin(x) + sin(x) - cos(x)
dfun(x) = -sin(x)
Out[2]:
In [3]:
function calc_integr{T<:Number, QT<:Jacobi.QUADRATURE_TYPE}(Q, a, b, ::Type{QT}=Jacobi.GLJ, ::Type{T}=Float64)
z = Jacobi.qzeros(QT, Q, a, b, T)
w = Jacobi.qweights(QT, z, a, b)
y = fun(z)
return sum(w .* y)
end
calc_integr(50, 1, 0, Jacobi.GLJ, BigFloat)
Out[3]:
In [4]:
set_bigfloat_precision(1024)
Iex{T<:Number}(::Type{T}=Float64) = ifun(one(T)) - ifun(-one(T))
Iex(BigFloat)
Out[4]:
In [5]:
Q = 2:40
tipo =BigFloat
Ie = Iex(tipo)
QT = Jacobi.GRJP
a = 1
b = 0
err = [abs(calc_integr(q, a, b, QT, tipo) - Ie) for q in Q];
In [6]:
using PyPlot
In [7]:
semilogy(Q, err, "o--")
Out[7]:
In [ ]:
In [8]:
function calc_deriv_err{T<:Number, QT<:Jacobi.QUADRATURE_TYPE}(Q, ::Type{QT}=Jacobi.GLJ, ::Type{T}=Float64)
z = Jacobi.qzeros(QT, Q, 0, 0, T)
w = Jacobi.qweights(QT, z, 0, 0)
D = Jacobi.qdiff(QT, z)
y = fun(z)
yex = dfun(z)
return maxabs(D * y - yex)
end
Out[8]:
In [9]:
Q = 2:40
tipo =BigFloat
QT = Jacobi.GLJ
derr = [calc_deriv_err(q, QT, tipo) for q in Q];
In [10]:
semilogy(Q, derr, "o--")
Out[10]: