rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
quadrature.m
1 function res = quadrature(weights,points,func,varargin)
2 %function res = quadrature(weights,points,func,varargin)
3 %
4 % integration of function func by given quadrature. func
5 % is a function getting a local coordinate vector and varargin
6 % and giving a (vectorial or scalar) result or a cell array of such.
7 % points is expected to be a npoints x dimpoint matrix
8 % result is the same size of f-evaluations.
9 % we emphasize, that also cell-array valued functions can be
10 % integrated (for use in rb-methods)
11 
12 % Bernard Haasdonk 27.8.2009
13 
14 npoints = length(weights);
15 if isempty(varargin)
16  f = func(points(1,:));
17  if ~iscell(f)
18  res = weights(1)*f;
19  for qp=2:npoints
20  f = func(points(qp,:));
21  res = res +weights(qp)*f;
22  end;
23  else % iscell!!
24  res = f;
25  for q = 1:length(f(:));
26  res{q} = weights(1)*f{q};
27  end;
28  for qp=2:npoints
29  f = func(points(qp,:));
30  for q = 1:length(f(:));
31  res{q} = res{q} +weights(qp)*f{q};
32  end;
33  end;
34  end;
35 else % not isempty varargin: same but different...
36  f = func(points(1,:),varargin{:});
37  if ~iscell(f)
38  res = weights(1)*f;
39  for qp=2:npoints
40  f = func(points(qp,:),varargin{:});
41  res = res +weights(qp)*func(points(qp,:),varargin{:});
42  end;
43  else % iscell
44  for q = 1:length(f(:));
45  res{q} = weights(1)*f{q};
46  end;
47  for qp=2:npoints
48  f = func(points(qp,:),varargin{:});
49  for q = 1:length(f(:));
50  res{q} = res{q} +weights(qp)*f{q};
51  end;
52  end;
53  end;
54 end;
55 
56 %| \docupdate