Filter löschen
Filter löschen

Multiple plot on same graph

3 Ansichten (letzte 30 Tage)
Hmm!
Hmm! am 3 Dez. 2021
Kommentiert: Walter Roberson am 3 Dez. 2021
I would like to have these 4 plots on the same graph sheet for easy comparison. Plotting the individual plot works but I am not sure what is the reason why all the 4 plots cannot be plotted at the same time. Relying on benevolent members for assitance.
rng default
n = 30;
% generate the A matrix
D = delsq(numgrid('L',n)); %same as matrix A
bGrid = ones(length(D),1); %same as RHS b vector
M = diag(diag(D));
tol = 1e-8;
maxit = 100;
P = inv(M);
L = ichol(M);
Q = ichol(M,struct('michol','on'));
% pcg
[x0,f0,r0,it0,rv0] = pcg(D,bGrid); %no precond
[x1,f1,r1,it1,rv1] = pcg(D,bGrid,tol,maxit,P); % inv
[x2,f2,r2,it2,rv2] = pcg(D,bGrid,tol,maxit,L,L'); % ichol
[x3,f3,r3,it3,rv3] = pcg(D,bGrid,tol,maxit,Q,Q'); % modified ichol
% plots on same graph
semilogy(0:length(rv0)-1,rv0/norm(bGrid),'-o')
hold on
semilogy(0:length(rv1)-1,rv1/norm(bGrid),'-o')
semilogy(0:length(rv2)-1,rv2/norm(bGrid),'-o')
semilogy(0:length(rv3)-1,rv3/norm(bGrid),'-o')
yline(tol,'r--');
legend('No Preconditioner', 'inv(M)', 'ichol(M)', 'michol(M)', 'Tolerance', 'Location','southwest')
title('Conjugant Gredient Algorithm');
legend('boxoff')

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 3 Dez. 2021
rng default
n = 30;
% generate the A matrix
D = delsq(numgrid('L',n)); %same as matrix A
bGrid = ones(length(D),1); %same as RHS b vector
M = diag(diag(D));
tol = 1e-8;
maxit = 100;
P = inv(M);
L = ichol(M);
Q = ichol(M,struct('michol','on'));
% pcg
[x0,f0,r0,it0,rv0] = pcg(D,bGrid); %no precond
[x1,f1,r1,it1,rv1] = pcg(D,bGrid,tol,maxit,P); % inv
[x2,f2,r2,it2,rv2] = pcg(D,bGrid,tol,maxit,L,L'); % ichol
[x3,f3,r3,it3,rv3] = pcg(D,bGrid,tol,maxit,Q,Q'); % modified ichol
% plots on same graph
semilogy(0:length(rv0)-1,rv0/norm(bGrid),'-or')
hold on
semilogy(0:length(rv1)-1,rv1/norm(bGrid),'--.g')
semilogy(0:length(rv2)-1,rv2/norm(bGrid),':^b')
semilogy(0:length(rv3)-1,rv3/norm(bGrid),'+k')
yline(tol,'r--');
legend('No Preconditioner', 'inv(M)', 'ichol(M)', 'michol(M)', 'Tolerance', 'Location','southwest')
title('Conjugant Gredient Algorithm');
legend('boxoff')
min(rv0),max(rv0)
ans = 1.8506
ans = 52.6747
min(rv1),max(rv1)
ans = 1.9799e-07
ans = 52.6747
min(rv2),max(rv2)
ans = 1.9799e-07
ans = 52.6747
min(rv3),max(rv3)
ans = 1.9799e-07
ans = 52.6747
You are asking to solve the same system of linear equations with different preconditioners, but you are expecting that the differences between the results will be visible on the plot.
There is a notable difference on the first point of rv0 versus the remainder, but on the scale of the plot you cannot tell by the plot.
  4 Kommentare
Hmm!
Hmm! am 3 Dez. 2021
Is that the case for what is here? Scroll down to see the plot.
Walter Roberson
Walter Roberson am 3 Dez. 2021
M = diag(diag(D));
That is a sparse diagonal matrix whose diagonal is the constant 4.
L = ichol(M);
That is a sparse diagonal matrix whose diagonal is the constant 2.
Your arrays are "boring" -- the hints you are providing through the additional parameters are adding essentially no usable new information, so the outputs are all the same (except being different sizes in some cases.)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Produkte


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by