Rank in Matlab shows different result than Mathematica

3 views (last 30 days)
Hello,
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.

Accepted Answer

Yuichi Tadokoro
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]
A =
[ 1 - sin(x)^2, cos(x)^2]
[ 1, 1]
>> rank(A)
ans =
2
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
>> rewrite(A,'cos')
ans =
[ cos(x)^2, cos(x)^2]
[ 1, 1]
>> rank(rewrite(A,'cos'))
ans =
1

More Answers (0)

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!