rbmatlab 0.10.01
|
00001 function res = quadrature(weights,points,func,varargin) 00002 %function res = quadrature(weights,points,func,varargin) 00003 % 00004 % integration of function func by given quadrature. func 00005 % is a function getting a local coordinate vector and varargin 00006 % and giving a (vectorial or scalar) result or a cell array of such. 00007 % points is expected to be a npoints x dimpoint matrix 00008 % result is the same size of f-evaluations. 00009 % we emphasize, that also cell-array valued functions can be 00010 % integrated (for use in rb-methods) 00011 00012 % Bernard Haasdonk 27.8.2009 00013 00014 npoints = length(weights); 00015 if isempty(varargin) 00016 f = func(points(1,:)); 00017 if ~iscell(f) 00018 res = weights(1)*f; 00019 for qp=2:npoints 00020 f = func(points(qp,:)); 00021 res = res +weights(qp)*f; 00022 end; 00023 else % iscell!! 00024 res = f; 00025 for q = 1:length(f(:)); 00026 res{q} = weights(1)*f{q}; 00027 end; 00028 for qp=2:npoints 00029 f = func(points(qp,:)); 00030 for q = 1:length(f(:)); 00031 res{q} = res{q} +weights(qp)*f{q}; 00032 end; 00033 end; 00034 end; 00035 else % not isempty varargin: same but different... 00036 f = func(points(1,:),varargin{:}); 00037 if ~iscell(f) 00038 res = weights(1)*f; 00039 for qp=2:npoints 00040 f = func(points(qp,:),varargin{:}); 00041 res = res +weights(qp)*func(points(qp,:),varargin{:}); 00042 end; 00043 else % iscell 00044 for q = 1:length(f(:)); 00045 res{q} = weights(1)*f{q}; 00046 end; 00047 for qp=2:npoints 00048 f = func(points(qp,:),varargin{:}); 00049 for q = 1:length(f(:)); 00050 res{q} = res{q} +weights(qp)*f{q}; 00051 end; 00052 end; 00053 end; 00054 end; 00055 00056 %| \docupdate