I am supposed to plot the size k of a Hilbert matrix and condition number . I am supposed to plot k = 5, 10, 15, 20, 25, 30 vs condition # wrt to 1-norm, cond inf-norm, cond 2-norm
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have the code below which outputs the respective matrices and condition numbers but I am confused on how I am supposed to plot the actual matrix vs the norms. code below;
k = [ 5 10 15 20 25 30];
for k = 1:5
hilbert = hilb(k)
cond(hilbert,2)
end
for n = 1:5
hilbert = hilb(k)
cond(hilbert,1)
end
for n = 1:5
hilbert = hilb(k)
cond(hilbert, inf)
end
%k = (5, 10, 15, 20, 25, 30);
%condNum = (1, 2, inf)
%plot(
Is there a better way to write the loop instead of repeating loops? Additionally, how would I plot the size versus the cond numbers ? Would it be better to do each separately for the three norms then record the values and then plot them? I am stuck on how to proceed and wonder if I am even writing this code correctly according to the instructions. Any pointers in the right direction would be greatly appreciated
0 commentaires
Réponses (1)
Dohyun Kim
le 27 Déc 2017
Modifié(e) : Dohyun Kim
le 27 Déc 2017
k = [5,10,15, 20, 25, 30];
cond1 = zeros(1,length(k));
cond2 = zeros(1,length(k));
condinf = zeros(1,length(k));
for i = 1 : length(k)
H = hilb(k(i));
cond1(i) = cond(H,1);
cond2(i) = cond(H,2);
condinf(i) = cond(H,inf);
end
plot(k,cond1,k,cond2,k,condinf)
I suggest you to use
semilogy(k,cond1,k,cond2,k,condinf)
instead of just plot. Since condition number grows fast, it is better to use log scale for y-axis
Also, you may get warning while get condition number for large k.
In my case, from k = 15, I get warning when we get condition number in 1-norm and inf-norm.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 2.765788e-19.
I think we cannot trust the result for k>=15.
However, result shows that they are bounded by 10^19 which appears to similar in the warning message.
FYI, RCOND is reciprocal of condition number (= 1/cond(A))
0 commentaires
Voir également
Catégories
En savoir plus sur Linear Algebra dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!