Matlab 符号工具箱:我的代码有什么问题?

发布于 2024-07-13 23:45:13 字数 682 浏览 6 评论 0原文

我正在尝试使用 Matlab 的符号工具箱求解未知数 x、y、z 中的三个联立非线性方程。 下面的代码有什么问题?

solve( '(x/4 + y/2 + z/4)*(1/(8*x) + 1/(16*y) + 1/(8*z))  = 0.5774',  ...
       '(x/4 + y/4 + z/2)*(1/(4*x) + 1/(16*y) + 1/(16*z)) = 0.5774',  ...
       '(x/2 + y/4 + z/4)*(1/(8*x) + 1/(8*y)  + 1/(16*z)) = 0.5774' )    

我收到以下错误:

??? Error using ==> subsref
Index exceeds matrix dimensions.

Error in ==> sym.subsref at 16
  y = builtin('subsref',struct(x),a);

Error in ==> solve at 191
      S.(char(symvars(j))) = R(:,j);

我使用的是 Matlab 版本 7.7.0.471。 我对符号工具箱一点也不熟悉。 我缺少什么?

我对符号引擎的期望是否太高了? 或者,有更好的方法来求解上述方程吗? (数值解即可。)

I'm trying to solve three simultaneous nonlinear equations in the unknowns x, y, z with Matlab's symbolic toolbox. What's wrong with the following code?

solve( '(x/4 + y/2 + z/4)*(1/(8*x) + 1/(16*y) + 1/(8*z))  = 0.5774',  ...
       '(x/4 + y/4 + z/2)*(1/(4*x) + 1/(16*y) + 1/(16*z)) = 0.5774',  ...
       '(x/2 + y/4 + z/4)*(1/(8*x) + 1/(8*y)  + 1/(16*z)) = 0.5774' )    

I get the following error:

??? Error using ==> subsref
Index exceeds matrix dimensions.

Error in ==> sym.subsref at 16
  y = builtin('subsref',struct(x),a);

Error in ==> solve at 191
      S.(char(symvars(j))) = R(:,j);

I'm using Matlab version 7.7.0.471. I'm not familiar at all with the symbolic toolbox. What am I missing?

Am I expecting too much from a symbolic engine? Or, are there better ways to solve the above equations? (A numerical solution will do.)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

戈亓 2024-07-20 23:45:13

你的语法是正确的,但我不认为你的方程组有解决方案。 当我将它们推送到 Mathematica 时,它返回一个空列表,这通常表明没有解决方案。

您使用的 MATLAB 版本使用 MuPad 作为符号计算引擎,但他们过去使用 Maple。 我有最新版本的 Maple 版本的符号工具箱,当我将你的表达式放入其中时,我得到了

Warning: Explicit solution could not be found.
 In solve at 140

ans =

[ empty sym ]

所以我建议这个方程组没有解,而新的 Mupad 符号引擎根本无法处理这个问题事实上非常优雅。

更新:尝试在 Mathematica 中以数值方式解决这个问题,无论我选择什么起始值,都会导致对奇异雅可比行列式的抱怨。 我只是不知道如何证明你的方程无解,但我强烈怀疑情况确实如此。

Your syntax is correct but I don't think that your system of equations has a solution. When I pushed them through Mathematica it returned an empty list which usually indicates that there is no solution.

The version of MATLAB you are using uses MuPad as it's symbolic computation engine but they used to use Maple. I have the most recent version of the Maple version of the symbolic toolbox and when I put your expression into it I get

Warning: Explicit solution could not be found.
 In solve at 140

ans =

[ empty sym ]

So I would suggest that there is no solution to this system of equations and the new Mupad symbolic engine simply doesn't handle this fact very elegantly.

Update: Attempting to solve this numerically in Mathematica results in complaints about a singular Jacobian no matter what starting values I choose. I simply do not know how to prove that your equations have no solution but I strongly suspect this is the case.

永言不败 2024-07-20 23:45:13

检查 Mike 建议的一种方法代码中发生的情况是在solve中的有问题的行设置一个断点并检查那里使用的变量的大小。 很可能,一个或多个的大小为 0。至于弄清楚数学上是否真的没有解决方案,我无法帮助您。 找一个数学研究生。

One way to check if what Mike suggested is happening in your code is to set a break point at the offending line in solve and check the sizes of the variables used there. Chances are, one or more has size 0. As to figuring out if there truly is no solution mathematically, I can't help you there. Find a math grad student.

网名女生简单气质 2024-07-20 23:45:13

看起来这可能是一个错误。 它看起来与此相同:

http://www.mathworks.com /support/bugreports/details.html?rp=501052

It looks like it might be a bug. It looks the same as this:

http://www.mathworks.com/support/bugreports/details.html?rp=501052

半世蒼涼 2024-07-20 23:45:13

像这样写你的代码

solve ('x+y+1','x+2*y-5');

那就没问题了。

   xx=[0:.1:5];
   yy=.2; 
   for i=1:50; 
       yy(i+1)= yy(i)+.1*yy(i)*(1-yy(i); 
   end; 
   plot(xx,yy)

Write your code like this

solve ('x+y+1','x+2*y-5');

That will be alright.

   xx=[0:.1:5];
   yy=.2; 
   for i=1:50; 
       yy(i+1)= yy(i)+.1*yy(i)*(1-yy(i); 
   end; 
   plot(xx,yy)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文