我是新来的线性代数和学习有关的三角系统实施朱莉娅郎。 我有一个 col_bs()function 我会在这里展示我需要做一个数学的发器计数。 它不必是超级技术,这是学习的目的。 我试图破坏功能下到它的内我循环和外j循环。 中间是一个计的每一个触发器,这是我的假设是没有用的,因为常量是通常下降。
我也知道答案应该是正^2因为它是一个颠倒版本的 转换算法,这是正^2发器. 我想我最好得出这N^2最但是当我想我结束了个奇怪的Nj计数。 我将尝试提供的所有工作我已经做了! 谢谢你对谁有帮助。
function col_bs(U, b)
n = length(b)
x = copy(b)
for j = n:-1:2
if U[j,j] == 0
error("Error: Matrix U is singular.")
end
x[j] = x[j]/U[j,j]
for i=1:j-1
x[i] = x[i] - x[j] * U[i , j ]
end
end
x[1] = x[1]/U[1,1]
return x
end
1: To start 2 flops for the addition and multiplication x[i] - x[j] * U[i , j ]
The $i$ loop does: $$ \sum_{i=1}^{j-1} 2$$
2: 1 flop for the division $$ x[j] / = U[j,j] $$
3: Inside the for $j$ loop in total does: $$ 1 + \sum_{i=1}^{j-1} 2$$
4:The $j$ loop itself does:$$\sum_{j=2}^n ( 1 + \sum_{i=1}^{j-1} 2)) $$
5: Then one final flop for $$ x[1] = x[1]/U[1,1].$$
6: Finally we have
$$\\ 1 + (\sum_{j=2}^n ( 1 + \sum_{i=1}^{j-1} 2))) .$$
Which we can now break down.
If we distribute and simplify
$$\\ 1 + (\sum_{j=2}^n + \sum_{j=2}^n \sum_{i=1}^{j-1} 2) .$$
We can look at only the significant variables and ignore constants,
$$\\
\\ 1 + (n + n(j-1))
\\ n + nj - n
\\ nj
$$
这就意味着,如果我们忽视常数的可能性最大的发器,为这个公式将$n$(可以是暗示什么错我的功能,因为它应该是$n^2元就像其余的我们的三角系统,我相信)