Numerical Solution of Partial Differential Equations作业要求
文件结构示例
| | --- nspde_yourID | |___________ figure | | |____________ fig2_2.fig | | |____________ fig2_2.eps | | . | | . | | | |___________ private | | |_____________ xx.m | | |_____________ xxx.m | | . | | . | | | |___________ homework1_dirver_yourID.m | |___________ homework2_driver_yourID.m | . . . . .
代码书写规范
程序示例
function [x,w,v] = chebpts(n, varargin)
%CHEBPTS Compute the second kind chebyshev points.
% [X,W,V] = CHEBPTS(N) retuns N Chebyshev points of the second kind in [-1, 1].
% X is the second kind Chebshev points, W is the weights of Clenshaw-Curtis
% quadrature, and V is the barycentric weights corresponding to the Chebyshev
% points X.
%
% [X,W,V] = CHEBPTS(N,[a,b]) retuns N Chebyshev points of the second kind in
% [a, b].
%
% Example:
%
% [x, w] = chebpts(10, [-2,2]);
% w*x.^2 % quadrature of x^2 in [-2,2]
%
% This programe is adapted from Chebfun/chebtech2.chebpts, http://www.chebfun.org/
if n == 1
x = 0;
w = 2;
v = 1;
else
% Chebyshev points:
m = n - 1;
x = sin(pi*(-m:2:m)/(2*m)).'; % (Use of sine enforces symmetry.)
% quadratrue weights
c = 2./[1, 1-(2:2:(m)).^2]; % Exact integrals of T_k (even)
c = [c, c(floor(n/2):-1:2)]; % Mirror for DCT via FFT
w = ifft(c); % Interior weights
w([1,n]) = w(1)/2; % Boundary weights
% barycentric interpolate weights
v = [0.5;ones(n-1,1)]; % Note v(1) is positive.
v(2:2:end) = -1;
v(end) = .5*v(end);
end
if nargin == 2
[x, w] = rescale(x, w, varargin{1});
end
end
function [x, w] = rescale(x, w, dom)
%RESCALE Rescale the quadrature points and weights.
a = dom(1);
b = dom(2);
w = .5*w*(b-a);
x = .5*(a+b) + .5*(b-a).*x;
end
作业提示
|