creating random dense symmetric matrix with desired condition number
6 次查看(过去 30 天)
显示 更早的评论
I want to test my code on a large size matrix which should a dense symmetric with specific condition number. I wonder if there are built-in functions in Matlab for doing that?
0 个评论
回答(1 个)
David Goodmanson
2017-5-8
编辑:David Goodmanson
2017-5-8
[modified to address the first comment below]
Hi othello, I don't know about built-in functions but there are ways to make your own matrices, e.g.
a = 2*rand(10,10)-1 + 2*rand(10,10)-1;
a = a+a'; % symmetric with random entries beween -2 and 2
C = 2345; % desired condition number
[u s v] = svd(a);
s = diag(s); % s is vector
% ===== linear stretch of existing s
s = s(1)*( 1-((C-1)/C)*(s(1)-s)/(s(1)-s(end))) ;
% =====
s = diag(s); % back to matrix
b = u*s*v';
cond(b)
ans = 2.3450e+03
%
%
% ===== log spacing example, where also norm(b) = 1 (induced matrix norm)
% s = exp(linspace(0,-log(C),length(s)));
% =====
The condition number is the ratio between the first and last diagonal entries in matrix s (which are sorted), so s is modified to make that ratio equal to C. This also works if the matrix has complex values and is Hermitian. You can also use normal random variables instead of uniform, etc. Seems to work, although something bad is going to happen eventually if you make C too large.
5 个评论
David Goodmanson
2017-5-10
编辑:David Goodmanson
2017-5-10
I forgot to mention in comments that I modified the code so now nothing is tbd. Works in every case I tried.
John D'Errico
2017-5-10
编辑:John D'Errico
2017-5-10
Yes. A complete linear or log transformation of the singular values will suffice. Anything like that will work, where all of the singular values move together. That way it does not allow the singular values to effectively change their sequence. Of course, if the small singular value was exactly zero, then there would be a problem. That event would be unlikely, starting from a random matrix. But even that can be solved. +1 now.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!