rbmatlab  1.13.10
 All Classes Namespaces Files Functions Variables Groups Pages
test_ldg_derivative.m
1 function OK = test_ldg_derivative
2 %function OK = test_ldg_derivative
3 %
4 % function testing, whether the ldg basis function derivatives
5 % gives approximately what is expected from finite differences.
6 
7 % Bernard Haasdonk 28.8.2009
8 
9 OK = 1;
10 
11 for pdeg = 0:4
12  params.nelements = 10;
13  params.dimrange = 3;
14  params.pdeg = pdeg;
15 % df = ldgdiscfunc(params);
16 
17  for j = 1:100;
18  x = rand(1,2);
19  h = 1e-8;
20 
21  DPhis = ldg_evaluate_basis_derivative(x,params);
22 
23  % for each basis function compute finite differences
24  Phis = ldg_evaluate_basis(x,params);
25  Phis_xph = ldg_evaluate_basis(x+[h,0],params);
26  Phis_yph = ldg_evaluate_basis(x+[0,h],params);
27 
28  nbasefunc = length(DPhis);
29  for i = 1:nbasefunc;
30  Dphi_appr = [Phis_xph(i,:)-Phis(i,:); Phis_yph(i,:)-Phis(i,:)]'/h;
31  maxerr = max(max(abs(Dphi_appr-DPhis{i})));
32  if maxerr>1e-3
33  OK = 0;
34  disp(['pdeg= ',num2str(pdeg),', i=',num2str(i),...
35  ',|DPhi-DPhi_appr|=',num2str(maxerr)])
36  keyboard;
37  error('ldg function derivatives not correct!');
38  end;
39  end;
40  end;
41 end;%| \docupdate