1 | % Plots the sparsity patterns of the Jacobian and the Hessian |
---|
2 | |
---|
3 | %%%%% JACOBIAN |
---|
4 | figure(1); |
---|
5 | |
---|
6 | J = zeros(NVAR,NVAR); |
---|
7 | for k=1:LU_NONZERO |
---|
8 | J( LU_IROW(k), LU_ICOL(k) ) = 1; |
---|
9 | end |
---|
10 | spy(J); |
---|
11 | TK = floor( linspace(1,NVAR,5) ); |
---|
12 | set(gca,'XTick',TK,'YTick',TK,'FontSize',14,'LineWidth',2); |
---|
13 | |
---|
14 | %%%%% HESSIAN |
---|
15 | figure(2); |
---|
16 | |
---|
17 | H = zeros(NVAR,NVAR,NVAR); |
---|
18 | for k=1:NHESS |
---|
19 | H( IHESS_I(k), IHESS_J(k), IHESS_K(k) ) = 1; |
---|
20 | H( IHESS_I(k), IHESS_K(k), IHESS_J(k) ) = 1; |
---|
21 | end |
---|
22 | |
---|
23 | M = ceil( sqrt(NVAR) ); |
---|
24 | |
---|
25 | for i=1:M |
---|
26 | for j=1:M |
---|
27 | k = M*(i-1)+j; |
---|
28 | if ( k <= NVAR ) |
---|
29 | subplot(M,M,k); |
---|
30 | hold on |
---|
31 | G = reshape( H(k,1:NVAR,1:NVAR), NVAR, NVAR ); |
---|
32 | % spy(G); figure;hold on |
---|
33 | for iH=1:NVAR; for jH=1:NVAR |
---|
34 | if( G(iH, jH) ) |
---|
35 | plot(iH,NVAR+1-jH,'.'); |
---|
36 | end; |
---|
37 | end; end |
---|
38 | text(NVAR/6,NVAR*0.6,int2str(k)) |
---|
39 | set(gca,'XLim',[1,NVAR],'YLim',[1,NVAR]); |
---|
40 | set(gca,'XTick',[],'YTick',[]); |
---|
41 | axis('square'); |
---|
42 | box on |
---|
43 | hold off; |
---|
44 | end |
---|
45 | end |
---|
46 | end |
---|