本文介绍了高斯消元与运营商定制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是实现高斯消元时,运营商定制的运营商,而不是标准的算术运算的人的好办法?

What is a good way to implement Gaussian elimination when the operators are custom operators, rather then standard arithmetic ones?

下面是运营商:

增加:

0 + 0 = 0
0 + 1 = 1
1 + 1 = 0

减法:

0 - 0 = 0
0 - 1 = 1
1 - 1 = 0

乘法:

0 * 0 = 0
0 * 1 = 0
1 * 1 = 1

师:

0 / 0 = illegal
0 / 1 = 0
1 / 1 = 1

下面是一个简单的方程组的增广矩阵,用RHS在最右边的列:

Here is a sample set of equations as augmented matrix, with the RHS in the right-most column:

1, 1, 0, 1, 0, 0, 0, 0, 0, 1
0, 1, 0, 1, 1, 0, 0, 0, 0, 1
0, 1, 1, 0, 0, 1, 0, 0, 0, 1
1, 0, 0, 1, 0, 0, 0, 0, 0, 1
0, 1, 0, 1, 1, 0, 0, 0, 0, 1
0, 0, 0, 0, 0, 1, 0, 0, 0, 1
0, 0, 0, 1, 0, 0, 1, 0, 0, 1
0, 0, 0, 1, 1, 0, 1, 1, 0, 1
0, 0, 0, 0, 0, 1, 0, 0, 1, 1

为这套解决方案是:

The solution for this set is:

x1 = 1
x2 = 0
x3 = 0
x4 = 0
x5 = 1
x6 = 1
x7 = 1
x8 = 1
x9 = 0

高斯消失败对我来说,因为我试过这一套。

方程将有9,16,25或36项。这将是巨大的,如果该算法很容易扩展到更大的广场,达100。我在寻找一种算法,在伪code或JavaScript preferably。

The equations will have 9, 16, 25 or 36 terms. It would be great if the algorithm is easily extendable to larger squares, up to 100.I'm looking for an algorithm, in pseudo code or JavaScript preferably.

推荐答案

高斯消元算法的伪code可以发现的。

Gaussian Elimination Algorithm in pseudocode can be found here.

这并不重要,如果您使用的是正常的数字或不管你是在Z轴环,该算法保持不变。

It doesn't matter if you are using 'normal' numbers or if you are in Z ring, the algorithm remains the same.

你可以做的是实现一个结构来保存你的工作在价值观和重载所有必要的运营商。然后,所有你需要做的将是改写伪code你想用它的语言。

What you could do is implement a structure to hold the values you are operating over and overload all necessary operators. Then all you need to do will be to rewrite pseudocode to the language you want to use it in.

不幸的是,因为你所提到的JavaScript,你不能覆盖该语言运营商因此这将变得更加复杂了一点。我想你可以定义将执行运营任务,并使用标准的运营商他们,而不是功能。

Unfortunately since you have mentioned JavaScript you cannot override operators in that language so this will become a bit more complex. I guess you could define functions that will perform operators job and use them instead of standard operators.

function add(v1, v2) {
    if ((v1 != 0 && v1 != 1) || (v2 != 0 && v2 != 1)) {
        alert('Invalid params');
        return;
    }

    return (v1 + v2) % 2;
}

function subtract(v1, v2) {
    if ((v1 != 0 && v1 != 1) || (v2 != 0 && v2 != 1)) {
        alert('Invalid params');
        return;
    }

    return Math.abs((v1 - v2) % 2);
}

function multiply(v1, v2) {
    if ((v1 != 0 && v1 != 1) || (v2 != 0 && v2 != 1)) {
        alert('Invalid params');
        return;
    }

    return v1 * v2;
}

function divide(v1, v2) {
    if ((v1 != 0 && v1 != 1) || (v2 != 0 && v2 != 1)) {
        alert('Invalid params');
        return;
    } else if (v2 == 0) {
        alert('Divider cannot be zero');
        return;
    }

    return v1 / v2;
}

这篇关于高斯消元与运营商定制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-16 16:33