#
#  Intgral æfingar úr kafla 5
#
#
#
#   [x,w]=qnwtrap(n,a,b)
#   [x,w]=qnwequi(n,a,b,type)
#
#
[x,w]=qnwtrap(10,-1,2)
integral=w'*exp(x);
#
#
[x,w]=qnwequi(100,-1,2,'N');
#
#
#
[x,w]=qnwtrap([10 20],[1 0],[2 5]);
integral = w'*exp(x(:,1)+x(:,2))
#
#
#
n=5
mu=0
var=1
[x,w]=qnwnorm(n,mu,var);
expectation=w'*exp(x)
#
# tvívítt
#
[x,w]=qnwnorm([10 15],[3 4],[2 -1; -1 4]);
expectation=w'*x
#
#
#
[x,w]=qnwlogn(n,mu,var);
[x,w]=qnwbeta(n,a,b);
[x,w]=qngamma(n,a);
#
# diffrun, bls 104.
#

function y=f(x)
y=x'*x
endfunction
#
#
#
fhess = fdhess('f',x)
#
#  takið eftir 'f'
#
function fjac=fdjac(f,x);
h=eps^(1/3)*max(abs(x),1);
xh1=x+h; xh0=x-h; hh=xh1-xh0;
for j=1:length(x);
   xx=x;
   xx(j)=xh1(j);f1=feval(f,xx);
   xx(j)=xh0(j);f0=feval(f,xx);
   fjac(:,j)=(f1-f0)/hh(j);
end
endfunction
#
#
#
 fdjac('f',x)



