在我所有的“家庭考试”之前,我总是有一个疯狂的、可能违反直觉的想法,那就是我可以创建一个列表,列出所有可能的公式组合。通过这样做,我可能能够将一些基本值输入到我从测试中得到的不同变量中,并得到适合问题的公式列表。基本示例:
欧姆定律
U = R * I
焦耳定律
P = U * I
但这两个列表可以合并:
P = R * I * I
或
I = U / R
这意味着
P = U * U / R
如何创建这些列表的所有可能组合?起初,我考虑创建不同的列表,例如
ohms_law = ['R', 'U', 'I']
jouls_law = ['P', 'U', 'I']
.
.
.
然而,这是实际连接它们的问题,以及实际等号、除号等放置在何处的问题
有谁能帮我更接近完成这个效率极低、毫无用处的想法吗?只是为了好玩
编辑:适用于教育程度较低、从未使用过配方奶粉的人
Formula 1: U = R * I
Formula 2: P = U * I
Output:
U = R * I
P = U * I
P = U * U / R
P = I * I * R
R = U / I
I = U / R
U = P / I
.
.
.
cont.
我在这里所做的只是将公式相互匹配。第一个公式表示U等于I乘以R。这意味着我们可以将它插入第二个公式,得到一个新的公式。我想要所有这些组合
这里有一个建议。最终的结果是错误的,我不想花太多时间修复bug,但是你可以看到我是如何解决这个问题的
例如,第一个结果是
R = * P
,这是错误的它试图用
'I = / U * P '
重新格式化'R = / I * U '
。但是I有维度-1,这没有被考虑进去。所以它看到两个U
,一个是维度1,一个是维度-1,并将它们抵消除了这些错误,你应该能够理解我是如何进行的
相关问题 更多 >
编程相关推荐