为什么将 `solve` 与多元方程组一起使用会意外出错?
Why does using `solve` with a multivariate system of equations error unexpectedly?
在尝试求解具有 2 个变量和 2 个未知数 (Izhikevich nullclines) 的方程组时,我遇到了意外错误:Warning: 4 equations in 2 variables.
和 Warning: Explicit solution could not be found.
这是出乎意料的,因为正如我所说,我只提供了带有 2 个变量的 2 个方程,这应该是一个格式正确的方程组。
我的相关代码行如下:
syms uu vv
[solvv, soluu] = solve([0.04*vv^2 + 5*vv + 140 - uu + I(t) == 0, a(t)*(b(t)*vv - uu) == 0], [vv, uu]);
完整的错误跟踪是:
Warning: 4 equations in 2 variables.
\> In C:\Program Files\MATLAB\R2012b\toolbox\symbolic\symbolic\symengine.p>symengine at 54
In mupadengine.mupadengine>mupadengine.evalin at 97
In mupadengine.mupadengine>mupadengine.feval at 150
In solve at 160
In Q3_new at 37
In run at 64
Warning: Explicit solution could not be found.
\> In solve at 169
In Q3_new at 37
In run at 64
困惑,我去了 MATLAB 的 documentation solve
并尝试使用示例片段来求解多元方程组:
syms u v
[solv, solu] = solve([2*u^2 + v^2 == 0, u - v == 1], [v, u])
根据文档,此代码段的预期输出是:
solv =
- (2^(1/2)*1i)/3 - 2/3
(2^(1/2)*1i)/3 - 2/3
solu =
1/3 - (2^(1/2)*1i)/3
(2^(1/2)*1i)/3 + 1/3
而是代码片段 returns:
Warning: 4 equations in 2 variables.
\> In C:\Program Files\MATLAB\R2012b\toolbox\symbolic\symbolic\symengine.p>symengine at 54
In mupadengine.mupadengine>mupadengine.evalin at 97
In mupadengine.mupadengine>mupadengine.feval at 150
In solve at 160
Warning: Explicit solution could not be found.
\> In solve at 169
solv =
[ empty sym ]
solu =
[]
和以前一样。
现在我知道我的代码没有犯一些初学者的错误,因为即使示例代码也以同样的方式出错。调用单变量示例代码片段按预期工作。我已经用 MATLAB 2012a 和 MATLAB 2014a 试过了。
什么可以解释这种异常行为?
可以在 MATLAB 2014a 上复制这个。我发现如果我已经使用 syms
定义了变量,您可以让 solve
自动解析变量。
syms u v
[sv, su] = solve([2*u^2 + v^2 == 0, u - v == 1], [v, u]) % Doesn't work
% works but order-unspecified so this is not desirable
[su, sv] = solve([2*u^2 + v^2 == 0, u - v == 1])
另一位用户指出了使用不正确文档的错误。 MATLAB 2014a uses the following notation instead for re-ordered solutions. The other form seems to be for 2015. You should probably verify this holds true in 2012a but it seems to do so
syms u v
[sv, su] = solve([2*u^2 + v^2 == 0, u - v == 1], v, u)
在尝试求解具有 2 个变量和 2 个未知数 (Izhikevich nullclines) 的方程组时,我遇到了意外错误:Warning: 4 equations in 2 variables.
和 Warning: Explicit solution could not be found.
这是出乎意料的,因为正如我所说,我只提供了带有 2 个变量的 2 个方程,这应该是一个格式正确的方程组。
我的相关代码行如下:
syms uu vv
[solvv, soluu] = solve([0.04*vv^2 + 5*vv + 140 - uu + I(t) == 0, a(t)*(b(t)*vv - uu) == 0], [vv, uu]);
完整的错误跟踪是:
Warning: 4 equations in 2 variables.
\> In C:\Program Files\MATLAB\R2012b\toolbox\symbolic\symbolic\symengine.p>symengine at 54
In mupadengine.mupadengine>mupadengine.evalin at 97
In mupadengine.mupadengine>mupadengine.feval at 150
In solve at 160
In Q3_new at 37
In run at 64
Warning: Explicit solution could not be found.
\> In solve at 169
In Q3_new at 37
In run at 64
困惑,我去了 MATLAB 的 documentation solve
并尝试使用示例片段来求解多元方程组:
syms u v
[solv, solu] = solve([2*u^2 + v^2 == 0, u - v == 1], [v, u])
根据文档,此代码段的预期输出是:
solv =
- (2^(1/2)*1i)/3 - 2/3
(2^(1/2)*1i)/3 - 2/3
solu =
1/3 - (2^(1/2)*1i)/3
(2^(1/2)*1i)/3 + 1/3
而是代码片段 returns:
Warning: 4 equations in 2 variables.
\> In C:\Program Files\MATLAB\R2012b\toolbox\symbolic\symbolic\symengine.p>symengine at 54
In mupadengine.mupadengine>mupadengine.evalin at 97
In mupadengine.mupadengine>mupadengine.feval at 150
In solve at 160
Warning: Explicit solution could not be found.
\> In solve at 169
solv =
[ empty sym ]
solu =
[]
和以前一样。
现在我知道我的代码没有犯一些初学者的错误,因为即使示例代码也以同样的方式出错。调用单变量示例代码片段按预期工作。我已经用 MATLAB 2012a 和 MATLAB 2014a 试过了。
什么可以解释这种异常行为?
可以在 MATLAB 2014a 上复制这个。我发现如果我已经使用 syms
定义了变量,您可以让 solve
自动解析变量。
syms u v
[sv, su] = solve([2*u^2 + v^2 == 0, u - v == 1], [v, u]) % Doesn't work
% works but order-unspecified so this is not desirable
[su, sv] = solve([2*u^2 + v^2 == 0, u - v == 1])
另一位用户指出了使用不正确文档的错误。 MATLAB 2014a uses the following notation instead for re-ordered solutions. The other form seems to be for 2015. You should probably verify this holds true in 2012a but it seems to do so
syms u v
[sv, su] = solve([2*u^2 + v^2 == 0, u - v == 1], v, u)