-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updates docs and cleans up files for differentiation and integration
of Legendre series. this fixes the behavior of intpol. Previously, intpol set the constant in a way that assumed you were resampling on the legendre nodes and cancelled the highest degree term. Now, this behvavior is only used for generating spectral differentiation matrices. Otherwise, the default is to give the coefficients of the true definite integral polynomial
- Loading branch information
1 parent
4736fd2
commit 8012c8b
Showing
4 changed files
with
101 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
function mat = dermat(k,u,v) | ||
%LEGE.DERMAT returns the spectral differentiation matrix on Legendre nodes | ||
% of order k | ||
% | ||
% input: | ||
% k - integer, number of Legendre nodes | ||
% | ||
% optional inputs: | ||
% u - k x k matrix mapping values at legendre nodes to legendre series | ||
% coefficients | ||
% v - k x k matrix mapping legendre series coefficients to values at | ||
% legendre nodes | ||
% | ||
% output: | ||
% mat - spectral differentiation matrix on Legendre nodes | ||
% | ||
%see also LEGE.EXPS, LEGE.DERPOL | ||
|
||
if nargin < 3 | ||
[~,~,u,v] = lege.exps(k); | ||
end | ||
|
||
mat = v(:,1:end-1)*lege.derpol(u); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,24 @@ | ||
function [aint,x,w] = intmat(n) | ||
function [aint,u,v] = intmat(n,u,v) | ||
%INTMAT returns the spectral integration matrix on n Gaussian nodes | ||
% a transcription of part of the Rokhlin routine legeinmt | ||
% | ||
% input: | ||
% n - the number of Gaussian nodes | ||
% | ||
% optional inputs: | ||
% u - k x k matrix mapping values at legendre nodes to legendre series | ||
% coefficients | ||
% v - k x k matrix mapping legendre series coefficients to values at | ||
% legendre nodes | ||
% | ||
% output: | ||
% | ||
|
||
[x,w,u,v] = lege.exps(n); | ||
if nargin < 3 | ||
[~,~,u,v] = lege.exps(n); | ||
end | ||
|
||
coeffs = eye(n); | ||
polints = lege.intpol(coeffs); | ||
aint = v*polints(1:end-1,:)*u; | ||
tmp = lege.intpol(u,'original'); | ||
aint = v*tmp(1:end-1,:); | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
% | ||
|
||
addpaths_loc(); | ||
|
||
k = 19; | ||
|
||
[x,w,u,v] = lege.exps(k); | ||
|
||
dmat = lege.dermat(k,u,v); | ||
imat = lege.intmat(k,u,v); | ||
|
||
pv = sin(x); | ||
dpv_true = cos(x); | ||
ipv_true = -cos(x)+cos(-1); | ||
|
||
dpv = dmat*pv; | ||
ipv = imat*pv; | ||
|
||
assert(norm(dpv-dpv_true) < 1e-12) | ||
assert(norm(ipv-ipv_true) < 1e-14) | ||
|
||
cfs = randn(k,1); | ||
cfsint1 = lege.intpol(cfs); | ||
cfsintold = lege.intpol(cfs,'original'); | ||
fun = @(t) lege.exev(t,cfs); | ||
|
||
for j = 1:k | ||
itrue = integral(fun,-1,x(j)); | ||
icoefs = lege.exev(x(j),cfsint1); | ||
assert(abs(itrue-icoefs)< 1e-14); | ||
end | ||
|