Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Algorithm 计算高阶多项式的算法(伪码)_Algorithm_Polynomial Math - Fatal编程技术网

Algorithm 计算高阶多项式的算法(伪码)

Algorithm 计算高阶多项式的算法(伪码),algorithm,polynomial-math,Algorithm,Polynomial Math,我需要一个算法来计算3个随机变量的高阶多项式,例如X,Y,Z 我需要高达9次的多项式。例如: Degree 2: X * Y X * Z Y * Z Degree 3: X * Y * Z X^2 * Y X^2 * Z Y^2 * X Y^2 * Z Z^2 * X Z^2 * Y . . . Degree 9: X^3*Y^3*Z^3 . . . 我相信三个内部“for-loop”可以解决这个问题,但我想不出来。 感谢您的帮助。 谢谢这里是一个蛮力Java解决方案。您只需迭代从到9(含9)

我需要一个算法来计算3个随机变量的高阶多项式,例如X,Y,Z

我需要高达9次的多项式。例如:

Degree 2:
X * Y
X * Z
Y * Z
Degree 3:
X * Y * Z
X^2 * Y
X^2 * Z
Y^2 * X
Y^2 * Z
Z^2 * X
Z^2 * Y
.
.
.
Degree 9:
X^3*Y^3*Z^3
.
.
.
我相信三个内部“for-loop”可以解决这个问题,但我想不出来。 感谢您的帮助。
谢谢

这里是一个蛮力Java解决方案。您只需迭代从到9(含9)的所有指数值,并保留总阶数小于或等于9的配置

for (int i=0; i <= 9; ++i) {
    for (int j=0; j <= 9; ++j) {
        for (int k=0; k <= 9; ++k) {
            if (i + j + k >= 2 && i + j + k <= 9) {
                System.out.println("x^" + i + "*y^" + j + "*z^" + k);
            }
        }
    }
}

for(inti=0;i)例如,在Python中,我将执行以下操作:

from itertools import permutations

for p in permutations([0,1,2,3] * 3,  3):

    if sum(p) >= 2:

        print("x^{} * y^{} * z^{}".format(*p))
基本上,循环遍历所有长度的3个系数排列
[0,1,2,3]*3
(0到3个重复3次)

下面是Heap生成排列算法的链接,以及一些伪代码:


…你用什么语言来实现?语言不重要,伪代码就足够了。作为参考,我必须用Ryo实现它。你将缺少两阶多项式。你计算的第一阶是x*y*z。你需要x^0,y^0和z^0。@TimBiegeleisen谢谢!这实际上完成了工作。蛮力的优势强制要求是您不必考虑太多。然而,这并不是实现它的最有效的方法。到目前为止,这是最好的答案!这可能在python中有效,但不是解决此问题的一般方法。
itertools
置换
在所有编程语言中都不可用。问题往往不是语言具体的。无论如何,谢谢。至少任何人都可以用任何语言查看如何编写置换算法。此外,这种方法可以很容易地扩展到10或20个变量(没有10或20个循环)。