On Thu, 30 Apr 2020, Alecos Papadopoulos wrote:
Maybe this is really a clarification on the theory, not on what gretl
does,
but I will start by asking here.
[...]
It's much easier than what you're making it. Just use the weights and
nodes in the "natural" way and you'll be ok. Example script follows:
<hansl>
nnodes = 7
# evaluate int_{0}^i exp(-x) dx
loop i = 1 .. 10 --quiet
scalar exact = 1 - exp(-i)
Q = quadtable(nnodes, 2, 0, i)
nodes = Q[,1]
wghts = Q[,2]
scalar approx = exp(-nodes)'wghts
printf "exact = %16.12f, approx = %16.12f, abs(diff) = %16.12f\n",
exact, approx, abs(exact-approx)
endloop
# evaluate int_{1}^{i/2} sin(x) dx
loop i = 3 .. 10 --quiet
scalar exact = cos(1) - cos(i/2)
Q = quadtable(nnodes, 2, 1, i/2)
nodes = Q[,1]
wghts = Q[,2]
scalar approx = sin(nodes)'wghts
printf "exact = %16.12f, approx = %16.12f, abs(diff) = %16.12f\n",
exact, approx, abs(exact-approx)
endloop
</hansl>
-------------------------------------------------------
Riccardo (Jack) Lucchetti
Dipartimento di Scienze Economiche e Sociali (DiSES)
Università Politecnica delle Marche
(formerly known as Università di Ancona)
r.lucchetti(a)univpm.it
http://www2.econ.univpm.it/servizi/hpp/lucchetti
-------------------------------------------------------