- Mathematica: http://www.wolframalpha.com/input/?i=rank(%7B%7B1-sin(x)%5E2,+cos(x)%5E2%7D,+%7B1,+1%7D%7D)
Rank in Matlab shows different result than Mathematica
5 views (last 30 days)
I'm working on a Matlab script that replaces a Mathematica script. I noticed that Matlab's rank and nullspace on a symbolic matrix show a different result compared to Matematica. Unfortunately, I do not have a minimal example at this point. The symbolic matrix is of size 100x10 and contains trigonometric functions. Using the same input for the rank in Matlab and Mathematica shows that Mathematica can eliminate one block of trigonometric functions more than Matlab. The problem is, that I can't prove which version is wrong.
Are there any tips for the symbolic toolbox in Matlab to prevent wrong assumptions on symbols or to simplify row reduction? At the moment I assume all symbols to be real, which is the case.
Also, in both Programs, the reduced echelon form shows the same issue. There are more non-identity rows in Matlab.
Thanks in advance.
Yuichi Tadokoro on 18 Jul 2018
For example, we have rank=2 in MATLAB and rank=1 in WolframAlpha for a matrix shown below.
>> syms x
>> A = [1-sin(x)^2 cos(x)^2; 1 1]
[ 1 - sin(x)^2, cos(x)^2]
[ 1, 1]
This issue is related to this topic: https://www.mathworks.com/help/symbolic/rank.html?s_tid=doc_ta#bupsf9u-1
The most general and practical workaround of this issue would be to use simplify or vpa before calling rank function.
In your case, the elements of the matrix are trigonometric functions, so rewrite function might help. https://www.mathworks.com/help/symbolic/rewrite.html
[ cos(x)^2, cos(x)^2]
[ 1, 1]