- Mathematica: http://www.wolframalpha.com/input/?i=rank(%7B%7B1-sin(x)%5E2,+cos(x)%5E2%7D,+%7B1,+1%7D%7D)
- MATLAB:
Rank in Matlab shows different result than Mathematica
1 view (last 30 days)
Show older comments
Chris B
on 13 Jul 2018
Answered: Yuichi Tadokoro
on 18 Jul 2018
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.
0 Comments
Accepted Answer
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
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
>> rewrite(A,'cos')
ans =
[ cos(x)^2, cos(x)^2]
[ 1, 1]
>> rank(rewrite(A,'cos'))
ans =
1
0 Comments
More Answers (0)
See Also
Categories
Find more on Calculus in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!