summaryrefslogtreecommitdiff
path: root/75/CH5/EX5.8/ex_8.sce
blob: d0d40fc93ecd3019a733627e02a08634e194f8c3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
        //    PG (278)

deff('[y]=f(x)','y=exp(-x^2)')
x0=0;
x1=1;


//    True value
I = integrate('exp(-x^2)','x',x0,x1)

//    Using Gaussian Quadrature

//    For n=2, w=1

n=2;
p  = legendrepol(n,'x')
xr = roots(p);
A  = [];

for j = 1:2
    pd = derivat(p)
    A = [A 2/((1-xr(j)^2)*(horner(pd,xr(j)))^2)]
end

tr = ((x1-x0)/2.*xr)+((x1+x0)/2);

s = ((x1-x0)/2)*f(tr)
I = s*A