如何用 solve 和 result 无根求解联立方程

how to solve simultaneous equations with solve and with result without roots

代码如下:

syms G1 G2 G3 M1 M2 M3 P1 P2 P3 D1 D2 D3
S = solve(0 == 0.9 * (20 - G1) - 0.012 * D3 * G1, ...
      0 == 0.9 * (20 - G2) - 0.012 * D1 * G2, ...
      0 == 0.9 * (20 - G3) - 0.012 * D2 * G3, ...
      0 == -0.0033 * M1 + 0.002 * G1, ...
      0 == -0.0033 * M2 + 0.002 * G2, ...
      0 == -0.0033 * M3 + 0.002 * G3, ...
      0 == 0.1 * M1 - 0.0033 * P1 + 2 * 0.5 * D1 - 2 * 0.025 * (P1 ^ 2), ...
      0 == 0.1 * M2 - 0.0033 * P2 + 2 * 0.5 * D2 - 2 * 0.025 * (P2 ^ 2), ...
      0 == 0.1 * M3 - 0.0033 * P3 + 2 * 0.5 * D3 - 2 * 0.025 * (P3 ^ 2), ...
      0 == -0.5 * D1 + 0.025 * (P1 ^ 2) + 0.9 * (20 - G2) - 0.012 * D1 * G2, ...
      0 == -0.5 * D2 + 0.025 * (P2 ^ 2) + 0.9 * (20 - G3) - 0.012 * D2 * G3, ...
      0 == -0.5 * D3 + 0.025 * (P3 ^ 2) + 0.9 * (20 - G1) - 0.012 * D3 * G1)

问题是我需要真正的解决方案,但我已经找到了有根的答案。我怎样才能得到真正的答案?

假设 "real solution" 你的意思是一个数值而不是确切的多项式根形式,有 two options 取决于你打算如何使用结果:

  1. double:这将评估 RootOf 表达式,假设没有自由参数,return class double。虽然输出现在仅限于双精度,但如果您的目标是在计算中使用根并关心性能,这是最快的选择。

  2. vpa: this will evaluate the RootOf expressions, assuming there are no free parameters, and return a Symbolic output of class sym. While the output is now able to be approximated to varying degrees of accuracy at evaluation by calling digits预先计算,由于其Symbolic性质,在后续计算中可能会有较大的计算开销。