⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tridisolve.m

📁 有趣的可视的数值方法 出自网站http://www.mathworks.com/moler
💻 M
字号:
function x = tridisolve(a,b,c,d)%   TRIDISOLVE  Solve tridiagonal system of equations.%     x = TRIDISOLVE(a,b,c,d) solves the system of linear equations%     b(1)*x(1) + c(1)*x(2) = d(1),%     a(j-1)*x(j-1) + b(j)*x(j) + c(j)*x(j+1) = d(j), j = 2:n-1,%     a(n-1)*x(n-1) + b(n)*x(n) = d(n).%%   The algorithm does not use pivoting, so the results might%   be inaccurate if abs(b) is much smaller than abs(a)+abs(c).%   More robust, but slower, alternatives with pivoting are:%     x = T\d where T = diag(a,-1) + diag(b,0) + diag(c,1)%     x = S\d where S = spdiags([[a; 0] b [0; c]],[-1 0 1],n,n)x = d;n = length(x);for j = 1:n-1   mu = a(j)/b(j);   b(j+1) = b(j+1) - mu*c(j);   x(j+1) = x(j+1) - mu*x(j);endx(n) = x(n)/b(n);for j = n-1:-1:1   x(j) = (x(j)-c(j)*x(j+1))/b(j);end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -