python统计分析中文版托马斯.pdf_三对角矩阵算法(TDMA)又名托马斯算法,在NumPy数组中使用Python...

这篇博客介绍了如何在Python中实现三对角矩阵算法(TDMA,又称托马斯算法),并用NumPy数组进行操作。作者展示了算法的代码,并在代码中进行了变量初始化,但当运行该算法与NumPy数组进行比较时,发现结果不同,暗示可能存在错误或不匹配的操作。
摘要由CSDN通过智能技术生成

function x = TDMAsolver(a,b,c,d)

%a, b, c are the column vectors for the compressed tridiagonal matrix, d is the right vector

n = length(b); % n is the number of rows

% Modify the first-row coefficients

c(1) = c(1)/b(1); % Division by zero risk.

d(1) = d(1)/b(1); % Division by zero would imply a singular matrix.

for i = 2:n-1

temp = b(i) - a(i) * c(i-1);

c(i) = c(i)/temp;

d(i) = (d(i) - a(i) * d(i-1))/temp;

end

d(n) = (d(n) - a(n) * d(n-1))/(b(n) - a(n) * c(n-1));

% Now back substitute.

x(n) = d(n);

for i = n-1:-1:1

x(i) = d(i) - c(i) * x(i + 1);

end

end

我需要它在python中使用numpy数组,这里我第一次尝试在python中的算法。

import numpy

aa = (0.,8.,9.,3.,4.)

bb = (4.,5.,9.,4.,7.)

cc = (9.,4.,5.,7.,0.)

dd = (8.,4.,5.,9.,6.)

ary = numpy.array

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值