Matlab Interprets Simple MuPad Code Differently than MuPad

2 Ansichten (letzte 30 Tage)
Tim Lewis
Tim Lewis am 12 Okt. 2012
When the Mupad code below is saved in a MuPad program file, it produces very different results depending on whether it is being run from a MuPad notebook or from the Matlab command window.
x:=0:
if x~=0 then
Result:="Program is being run from MuPad":
else
Result:="Program is being run from Matlab":
end_if:
return(Result)
Basically, MuPad is interpreting ~= as the _approx function and Matlab is interpreting it as meaning "not equal." This caused code that had been working fine in Matlab 2010a to produce incorrect results when run from Matlab 2012b.
Currently, I am just calling the _approx function directly instead of using ~=, but it seems that MuPad code should be interpreted the same way whether it is being run from a MuPad notebook or from a Matlab script. Is this a bug, or is it the intended behavior?
  2 Kommentare
Walter Roberson
Walter Roberson am 12 Okt. 2012
How are you triggering running the file from the MATLAB command window ?
Tim Lewis
Tim Lewis am 15 Okt. 2012
I use the following code:
feval(symengine,'reset');
feval(symengine,'read','"MyProgram.mu"');
Where "MyProgram.mu" contains the code from my original question.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Wendy Fullam
Wendy Fullam am 16 Okt. 2012
From development: The behavior is as designed and not a bug.
The Symbolic Math Toolbox (MATLAB side) uses a special definition of ~= which overrides MuPAD’s ~= . This means that MuPAD’s ~= no longer means “approximately equal”, but “unequal” like in MATLAB.
An easier example to see this is
evalin(symengine,'bool(1~=0)')
which returns TRUE in MATLAB since 1 is not equal to 0, but FALSE in MuPAD since they are not approximately equal.
  2 Kommentare
Tim Lewis
Tim Lewis am 16 Okt. 2012
Okay, so I understand that Matlab uses a definition of ~= that is consistent with the rest of Matlab syntax, but if they are going to switch the behavior in one place, it seems that they should switch the behavior everywhere. The way ~= is currently interpreted is confusing and can cause serious problems since it is interpreted in opposite ways in different places. If nothing else, there should at least be some way of communicating to the user that the use of ~= can be problematic (maybe a note in the help file, an mlint message, or something like that).
Walter Roberson
Walter Roberson am 16 Okt. 2012
I agree. And we need to know what else might have a "special definition".

Melden Sie sich an, um zu kommentieren.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by