x=[0., 0.5384693101056829, -0.5384693101056829, 0.9061798459386638, -0.9061798459386638] A=[x.^0 x.^1 x.^2 x.^3 x.^4]' B=[2,0,2/3,0,2/5] W=A\B a=0 b=2 m=30000 h=(b-a)/m function myf(x) abs(x-sqrt(2)) end function quad(f) W'*f.(x) end function myg(j,x) h/2*myf(x*h/2+a+h*j+h/2) end function comp(f) s=0 for i=0:(m-1) s=s+quad(x->myg(i,x)) end return s end ap=comp(myf) ex=4-2*sqrt(2) er=ap-ex println("m=",m," er=",er) println("ap=",ap) println("ex=",ex)