Matlab using Maple symbolic engine suddenly and oddly don't run in certain loop.

5 次查看(过去 30 天)
for i=1:1000
Firstly, my code can successfully run through loop.
But, at a certain i, such as i = 137 or 152 and so on, the problem is occur, that is
  1. the program seems like paused, the 'command window' no longer output value of variables which successfully output in the same previous loop.
  2. And when I try to pause the program using 'pause' button but the 'pausing' always shows, no response, even though after 12 hours or more.
  3. Meanwhile, the CPU occupied by Matlab is zero when getting into trouble.
  4. There is another odd thing, when I use 'Run and Advance' for this same code, the code sometimes run well, no bad thing happens, however, sometimes the problem occurs as usual.
So, What the problem is? And does it caused by Maple symbolic engine? Because when I use MuPAD there is no such problem.
Matlab 2017a and Maple 2018.
  3 个评论
zhang sifei
zhang sifei 2019-11-13
The structure of my program is almost like the following code, which is a simplified version. And this program doesn't occur the problem like what I described in the question.
for i=1:3000
syms x y z;
eqns=sym('eqns',[1 3]);
u=[x+2*y+3;y-4*z;2*z+5*y-x/2];
v=[2*x+y;4*y-z;5*z+2*y-x];
% To obatain eqns.
for j=1:3
eqns(j,1)=maple('simplify',u(j,1)-v(j,1));
end
% Convert eqns to matrix.
maple('with(LinearAlgebra):');
var=[x;y;z];
eqns_list = maple('convert', eqns, 'list');
vars_list = maple('convert', var, 'list');
B=maple('GenerateMatrix',eqns_list, vars_list, 'augmented=true', 'outputoptions=[storage=sparse]')
% Convert Symbolic matrix B into numerical matrix B_.
B_=eval(B);
B_num=B_(:,1:totnode);
b=B_(:,totnode+1);
% Solve B_num*x=b;
% By the way, u=maple('LinearSolve',B_) can also be used to solve B_num*x=b, however the problem occurs as usual.
end
After debug my wrong code, I find that
  • In differrent i loop, the following code sometimes run fast, but sometimes run slow. Why? it's odd. So, I thought that the problem may happended here.
B=maple('GenerateMatrix',eqns_list, vars_list, 'augmented=true', 'outputoptions=[storage=sparse]')
B_=eval(B);
  • Meanwhile, When I debug the code, the problem doesn't occur, everything are fine. However, when I directly run my code, the problem occurs as usual. More sad thing is that the problem doesn't occurs in same i loop at every time when I run the code.
What's wrong???
Stephen23
Stephen23 2019-11-26
编辑:Stephen23 2019-11-26
zhang sifei's "Answer" moved here:
I think the cause of this problem may occurs here
The wrong code is
T(i,1)=T(i,1)+w*(u(j,1)-u(i,1))*v*f;
and the sym/subsasgn (line 64) is
Does anybody tell me how to solve it?

请先登录,再进行评论。

回答(1 个)

Walter Roberson
Walter Roberson 2019-11-26
B_=eval(B);
You should never eval() a symbolic expression. The internal language used by the character representation of symbolic expressions is not the language of MATLAB itself, and is not the the internal symbolic toolbox language. This is true for both the Maple based symbolic engine and the later MuPAD based symbolic engine.
You should instead subs() for any variables you want to replace with values from the workspace, and possibly double() the result to make it numeric.
  6 个评论

请先登录,再进行评论。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by