/ concept-collection / windowedFourierProjection
Sign in
concept-collection / windowedFourierProjection
windowedFourierProjection / wfp_1Dspringscattering / utils / mktab_wts.m
57 lines · 1.4 KBBlameHistoryRaw
1function wts = mktab_wts(fun, chebApproxInfo)
2% MKTAB_WTS make a table of function values over cheb nodes in subintervals
3% of domain [ax,bx]
4%
5% INPUTs:
6% fun: function handle
7% chebApproxInfo.domain: domain [ax,bx] overwhich wts are computed.
8% chebApproxInfo.ninters: number of subintervals
9% chebApproxInfo.nord: order of polynomial interpolation; number of cheb
10% nodes
12% OUTPUT
13% wts(norder,ninters): table of cheb weights in each of
14% the subintervals where cheb poly approximation is applied
16% NOTE: code adjusted from code provided by Leslie Greengard.
18if(nargin == 0), test_mktab_wts; return; end
20nord = chebApproxInfo.nord;
21ninters = chebApproxInfo.ninters;
22domain = chebApproxInfo.domain;
23ax = domain(1); bx = domain(2);
25% Define function
26% fun = @(x) ...;
28% Preallocate the output matrix
29wts = zeros(nord, ninters);
31h = (bx - ax)/ninters;
33for iint = 1:ninters
34 A = ax + (iint - 1)*h;
35 B = ax + iint*h;
37 % Get Chebyshev nodes and sine values
38 [CHPTS,~,~,~,~,~] = chnodc(A, B, nord);
39 wts(:, iint) = chexfcdir(fun(CHPTS), nord);
40end
41end
43function test_mktab_wts
44ninters = 10; % Number of intervals
45nord = 5; % Order for Chebyshev nodes
46fun = @(x) cos(x - 3).*exp(-2*x);
48ax = -1; bx = 1;
49chebApproxInfo.nord = nord;
50chebApproxInfo.ninters = ninters;
51chebApproxInfo.domain = [ax,bx];
53wtsTab = mktab_wts(fun, chebApproxInfo);
55disp('Function at cheb nodes in subintervals:');
56disp(wtsTab);
57end
moveopenescclose