Why does MatLab give non integer values for whole numbers?
5 ビュー (過去 30 日間)
古いコメントを表示
I noticed MatLab sometimes gives ridiculous answers to obvious problems. As an example, I gave it a 2x2 matrix and asked it to give me the null.
A = [1 -1; -2 2]
B = null(A)
it prints out that B is [985/1393; 985/1393] or [0.7071; 0.7071] depending on format.
The answer should be B = [1; 1]
Any thoughts on how to fix this? It has become a problem as sometimes the answer has been 0.7071.
AS an example doing QR factorization of A = [-4 -1; 4 0] yields Q = [-0.7071 0.7071; 0.7071 0.7071]
[Q, R] = qr(A)
0 件のコメント
採用された回答
John D'Errico
2024 年 12 月 13 日
編集済み: Walter Roberson
2024 年 12 月 13 日
It is not even remotely ridiculous.
Are you seriously claiming that the vector [0.7071;0.7071] is NOT a null vector?
Any multiple of the vector [1;1] is as equally a valid result. If you don't like how it is normalized, then there is no reason you cannot normalize it yourself.
Why is it that you will sometimes see different normalizations? The Symbolic toolbox makes a different choice of how to normalize things. But since the normalization is completely and absolutely irrelevant, why do you care?
A = [1 -1;-2 2];
null(A)
null(sym(A)), disp(char(ans))
So your "problem" stems from the fact that SOMETIMES, you are computing a nullspace vector from a symbolic array, and other times, you are working from an array of doubles. When called with a double array, null automatically normalizes the vector to have unit 2-norm, ergo the 0.7071.
Either result is equally valid, and equally easy to change if you don't like it,
3 件のコメント
John D'Errico
2024 年 12 月 13 日
Personally, I would have written the two versions of null to be consistent. But if I ruled the world, well, you know.
Steven Lord
2024 年 12 月 13 日
When a problem has multiple solutions, sometimes determining which is the "easiest" solution can be tricky. See for example this post from Cleve Moler's blog: The World's Simplest Impossible Problem.
Is 3 and 3 the "easiest" solution to the problem Cleve posed? Or is it 0 and 6? 2 and 4?
But if you want a solution that "looks nicer", you can do that with the "rational" option for the null function to return rational answers. [Be sure to read the caution in the Description section for that syntax.]
A = [1 -1; -2 2]
N = null(A, "rational")
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Digital Filtering についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!