필터 지우기
필터 지우기

Multiple plot on same graph

조회 수: 3 (최근 30일)
Hmm!
Hmm! 2021년 12월 3일
댓글: Walter Roberson 2021년 12월 3일
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')

채택된 답변

Walter Roberson
Walter Roberson 2021년 12월 3일
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
Hmm!
Hmm! 2021년 12월 3일
Is that the case for what is here? Scroll down to see the plot.
Walter Roberson
Walter Roberson 2021년 12월 3일
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.)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by