Rank in Matlab shows different result than Mathematica

조회 수: 1 (최근 30일)
Chris B
Chris B 2018년 7월 13일
답변: Yuichi Tadokoro 2018년 7월 18일
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.

채택된 답변

Yuichi Tadokoro
Yuichi Tadokoro 2018년 7월 18일
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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Conversion Between Symbolic and Numeric에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by