Create random symmetric matrix with given cond number to pass it to pcg

1 Ansicht (letzte 30 Tage)
I want to generate random positive definitive symmetric matrix with given cond number, but the requirement is that PCG method should be able to solve it.
For now I use generation algorithm from this question. It does generate positive definitive symmetric random matrix with given cond number, but that is insufficient - pcg can't solve it even for smaller cond numbers. Pcg returns flag 4, which means that during algo it simply couldn't converge.
What am I doing wrong? Maybe there is better generating algorithm?
  3 Kommentare
Fedor
Fedor am 11 Mär. 2023
The question is to generate matrix that COULD BE solved with pcg. I don't know the exact requirements of pcg honestly, but somehow it doesn't work at all with the generated matrix. So the question is, what can I tweak(or use different generation scheme) to make it work with pcg.
Bruno Luong
Bruno Luong am 11 Mär. 2023
Bearbeitet: Bruno Luong am 11 Mär. 2023
" I don't know the exact requirements of pcg honestly"
positive definitive symmetric matrix.
For now I use generation algorithm from this question. It does generate positive definitive symmetric
That's the problem, the algo in the question you quote: it does not generate positive matrix as you freely believe.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Bruno Luong
Bruno Luong am 11 Mär. 2023
Bearbeitet: Bruno Luong am 11 Mär. 2023
n=10; % size of the system
condtarget = 1000;
% generate ransom spd matrix
[Q,~]=qr(randn(n));
r = rand(n,1);
r = (r-min(r))/(max(r)-min(r));
d=exp(r*log(condtarget));
A=Q'*diag(d)*Q
A = 10×10
61.2024 -52.3506 27.1572 10.1916 118.5038 -113.6603 51.9942 -15.6576 -36.1866 109.5894 -52.3506 54.0514 -19.7241 -14.7610 -97.4491 87.4631 -32.2037 3.9605 42.6244 -86.2163 27.1572 -19.7241 29.1843 -4.9656 72.9204 -77.2442 51.5620 -24.5594 -0.4552 73.7767 10.1916 -14.7610 -4.9656 21.8040 1.0998 8.1654 -16.8520 16.4248 -25.5273 -1.6470 118.5038 -97.4491 72.9204 1.0998 268.0601 -267.1190 146.9383 -59.9157 -45.3570 252.8113 -113.6603 87.4631 -77.2442 8.1654 -267.1190 279.6934 -160.8428 75.6400 28.7756 -258.5791 51.9942 -32.2037 51.5620 -16.8520 146.9383 -160.8428 113.5783 -59.3649 9.2172 151.0077 -15.6576 3.9605 -24.5594 16.4248 -59.9157 75.6400 -59.3649 46.1361 -20.6404 -68.2077 -36.1866 42.6244 -0.4552 -25.5273 -45.3570 28.7756 9.2172 -20.6404 52.0456 -32.5408 109.5894 -86.2163 73.7767 -1.6470 252.8113 -258.5791 151.0077 -68.2077 -32.5408 249.8764
cond(A)
ans = 1000.0000
b=rand(n,1) % random rhs
b = 10×1
0.9430 0.1720 0.2828 0.8032 0.5086 0.7290 0.0177 0.6979 0.9675 0.4766
x=pcg(A,b)
pcg stopped at iteration 10 without converging to the desired tolerance 1e-06 because the maximum number of iterations was reached. The iterate returned (number 10) has relative residual 0.00018.
x = 10×1
0.5857 -0.1797 0.0410 0.2153 0.1729 0.2925 0.0105 0.0112 0.5916 -0.1261
A*x % should close to b
ans = 10×1
0.9428 0.1718 0.2827 0.8033 0.5085 0.7288 0.0177 0.6980 0.9676 0.4766

Weitere Antworten (0)

Kategorien

Mehr zu Operating on Diagonal Matrices finden Sie in Help Center und File Exchange

Produkte


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by