chebfun 包的安装与使用
最近在学习如何使用chebfun包,以防自己忘记随手记录博客
Matlab安装
官方文档可见链接:
Guide
下载后并解压,在当前文件夹下,在命令行窗口输入
movefile('chebfun-master', 'chebfun'), addpath(fullfile(cd,'chebfun')), savepath
下面运行一个demo测试是否安装成功
x = chebfun('x');
f = sin(12*x).*exp(-x); % A function on [-1, 1]
g = max(f, 1./(x+2)); % The max of f and 1./(x+2)
plot(g) % A function with discontinuous derivative
sum(g) % The integral of g
plot(diff(g)) % The derivative of g
h = g + x - .8; % A function with several roots in [-1, 1]
rr = roots(h); % Compute the roots of h
plot(h, 'k', rr, h(rr), 'ro') % Plot h and its roots
可得结果
ans =
1.4619
及图片
MATLAB中利用Chebfun求解PDE实例
mathworks关于Chebfun包的详解链接: chebfun_mathworks
UU = PDE15s(PDEFUN, TT, U0, BC) where PDEFUN is a handle to a function with
arguments u, t, x, and D, TT is a vector, U0 is a CHEBMATRIX, and BC is a
chebop boundary condition structure will solve the PDE dUdt = PDEFUN(UU, t,
x) with the initial condition U0 and boundary conditions BC over the time
interval TT.
例1 Kuramoto-Sivashinsky 方程
一个非线性偏微分方程
x = chebfun('x');
u = 1 + 0.5*exp(-40*x.^2);
bc.left = @(u) [u - 1 ; diff(u)];
bc.right = @(u) [u - 1 ; diff(u)];
f = @(u) u.*diff(u) - diff(u, 2) - 0.006*diff(u, 4);
opts = pdeset('Ylim', [-30 30], 'PlotStyle', {'LineWidth', 2});
uu = pde15s(f, 0:.01:.5, u, bc, opts);
surf(uu, 0:.01:.5)
例 2 Nonuniform advection方程
x = chebfun('x', [-1 1]);
u = exp(3*sin(pi*x));
f = @(t, x, u) -(1 + 0.6*sin(pi*x)).*diff(u) + 5e-5*diff(u, 2);
opts = pdeset('Ylim', [0 20], 'PlotStyle', {'LineWidth', 2});
uu = pde23t(f, 0:.05:3, u, 'periodic', opts);
surf(uu, 0:.05:3)
例3 Chemical reaction (system)
x = chebfun('x');
u = [ 1 - erf(10*(x+0.7)) ; 1 + erf(10*(x-0.7)) ; 0 ];
f = @(u, v, w) [ .1*diff(u, 2) - 100*u.*v ; ...
.2*diff(v, 2) - 100*u.*v ; ...
.001*diff(w, 2) + 2*100*u.*v ];
opts = pdeset('Ylim', [0 2], 'PlotStyle', {'LineWidth', 2});
[t, u, v, w] = pde15s(f, 0:.1:3, u, 'neumann', opts);
mesh(uu{3})
Python安装
安装命令
pip install pychebfun