-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathirbleigs.m
More file actions
1526 lines (1329 loc) · 63.6 KB
/
irbleigs.m
File metadata and controls
1526 lines (1329 loc) · 63.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
function varargout = irbleigs(varargin)
% IRBLEIGS: Finds a few eigenvalues and eigenvectors of a Hermitian matrix.
%
% IRBLEIGS will find a few eigenvalues and eigenvectors for either the
% standard eigenvalue problem A*x = lambda*x or the generalized eigenvalue
% problem A*x = lambda*M*x, where A is a sparse Hermitian matrix and the
% matrix M is positive definite.
%
% [V,D,PRGINF] = IRBLEIGS(A,OPTIONS)
% [V,D,PRGINF] = IRBLEIGS(A,M,OPTIONS)
% [V,D,PRGINF] = IRBLEIGS('Afunc',N,OPTIONS)
% [V,D,PRGINF] = IRBLEIGS('Afunc',N,M,OPTIONS)
%
% The first input argument into IRBLEIGS can be a numeric matrix A or an M-file
% ('Afunc') that computes the product A*X, where X is a (N x blsz) matrix. If A is
% passed as an M-file then the (N x blsz) matrix X is the first input argument, the
% second input argument is N, (the size of the matrix A), and the third input argument
% is blsz, i.e. Afunc(X,N,blsz). For the generalized eigenvalue problem the matrix M is
% positive definite and passed only as a numeric matrix. IRBLEIGS will compute the
% Cholesky factorization of the matrix M by calling the internal MATLAB function CHOL.
% M may be a dense or sparse matrix. In all the implementations IRBLEIGS(A,...) can
% be replaced with IRBLEIGS('Afunc',N,...).
%
% NOTE: If the M-file 'Afunc' requires additional input parameters, e.g. a data structure,
% use the option FUNPAR to pass any additional parameters to your function (X,N,blsz,FUNPAR).
%
% OUTPUT OPTIONS:
% ---------------
%
% I.) IRBLEIGS(A) or IRBLEIGS(A,M)
% Displays the desired eigenvalues.
%
% II.) D = IRBLEIGS(A) or D = IRBLEIGS(A,M)
% Returns the desired eigenvalues in the vector D.
%
% III.) [V,D] = IRBLEIGS(A) or [V,D] = IRBLEIGS(A,M)
% D is a diagonal matrix that contains the desired eigenvalues along the
% diagonal and the matrix V contains the corresponding eigenvectors, such
% that A*V = V*D or A*V = M*V*D. If IRBLEIGS reaches the maximum number of
% iterations before convergence then V = [] and D = []. Use output option
% IV.) to get approximations to the Ritz pairs.
%
% IV.) [V,D,PRGINF] = IRBLEIGS(A) or [V,D,PRGINF] = IRBLEIGS(A,M)
% This option returns the same as (III) plus a two dimensional array PRGINF
% that reports if the algorithm converges and the number of matrix vector
% products. If PRGINF(1) = 0 then this implies normal return: all eigenvalues have
% converged. If PRGINF(1) = 1 then the maximum number of iterations have been
% reached before all desired eigenvalues have converged. PRGINF(2) contains the
% number of matrix vector products used by the code. If the maximum number of
% iterations are reached (PRGINF(1) = 1), then the matrices V and D contain any
% eigenpairs that have converged plus the last Ritz pair approximation for the
% eigenpairs that have not converged.
%
% INPUT OPTIONS:
% --------------
%
% ... = IRBLEIGS(A,OPTS) or ... = IRBLEIGS(A,M,OPTS)
% OPTS is a structure containing input parameters. The input parameters can
% be given in any order. The structure OPTS may contain some or all of the
% following input parameters. The string for the input parameters can contain
% upper or lower case characters.
%
% INPUT PARAMETER DESCRIPTION
%
% OPTS.BLSZ Block size of the Lanczos tridiagonal matrix.
% DEFAULT VALUE BLSZ = 3
%
% OPTS.CHOLM Indicates if the Cholesky factorization of the matrix M is available. If
% the Cholesky factorization matrix R is available then set CHOLM = 1 and
% replace the input matrix M with R where M = R'*R.
% DEFAULT VALUE CHOLM = 0
%
% OPTS.PERMM Permutation vector for the Cholesky factorization of M(PERMM,PERMM).
% When the input matrix M is replaced with R where M(PERMM,PERMM)=R'*R
% then the vector PERMM is the permutation vector.
% DEFAULT VALUE PERMM=1:N
%
% OPTS.DISPR Indicates if K Ritz values and residuals are to be displayed on each
% iteration. Set positive to display the Ritz values and residuals on
% each iteration.
% DEFAULT VALUE DISPR = 0
%
% OPTS.EIGVEC A matrix of converged eigenvectors.
% DEFAULT VALUE EIGVEC = []
%
% OPTS.ENDPT Three letter string specifying the location of the interior end-
% points for the dampening interval(s).
% 'FLT' - Let the interior endpoints float.
% 'MON' - Interior endpoints are chosen so that the size of the
% dampening interval is increasing. This creates a nested
% sequence of intervals. The interior endpoint will approach
% the closest Ritz value in the undampened part of the spectrum
% to the dampening interval.
% DEFAULT VALUE ENDPT = 'MON' (If SIGMA = 'LE' or 'SE'.)
% DEFAULT VALUE ENDPT = 'FLT' (If SIGMA = a numeric value NVAL.)
%
% OPTS.FUNPAR If A is passed as a M-file then FUNPAR contains any additional parameters
% that the M-file requires in order to compute the matrix vector product.
% FUNPAR can be passed as any type, numeric, character, data structure, etc. The
% M-file must take the input parameters in the following order (X,n,blsz,FUNPAR).
% DEFAULT VALUE FUNPAR =[]
%
% OPTS.K Number of desired eigenvalues.
% DEFAULT VALUE K = 3
%
% OPTS.MAXIT Maximum number of iterations, i.e. maximum number of block Lanczos restarts.
% DEFAULT VALUE MAXIT = 100
%
% OPTS.MAXDPOL Numeric value indicating the maximum degree of the dampening
% polynomial allowed.
% DEFAULT VALUE MAXDPOL = 200 (If SIGMA = 'LE' or 'SE'.)
% DEFAULT VALUE MAXDPOL = N (If SIGMA = a numeric value NVAL.)
%
% OPTS.NBLS Number of blocks in the Lanczos tridiagonal matrix. The program may increase
% NBLS to ensure certain requirements in [1] are satisfied. A warning message
% will be displayed if NBLS increases.
% DEFAULT VALUE NBLS = 3
%
% OPTS.SIGMA Two letter string or numeric value specifying the location
% of the desired eigenvalues.
% 'SE' Smallest Real eigenvalues.
% 'LE' Largest Real eigenvalues.
% NVAL A numeric value. The program searches for the K closest
% eigenvalues to the numeric value NVAL.
% DEFAULT VALUE SIGMA = 'LE'
%
% OPTS.SIZINT Size of the dampening interval. Value of 1 indicates consecutive
% Ritz values are used to determine the endpoints of the dampening
% interval. Value of 2 indicates endpoints are chosen from Ritz
% values that are seprated by a single Ritz value. A value of 3
% indicates endpoints are chosen from Ritz values that are seprated
% by two Ritz values. Etc. The minimum value is 1 and the maximum
% value is (NBLS-1)*BLSZ-K. The program may modify SIZINT without
% notification to ensure certain requirements in [1] are satisfied.
% DEFAULT VALUE SIZINT = 1
%
% OPTS.TOL Tolerance used for convergence. Convergence is determined when
% || Ax - lambda*x ||_2 <= TOL*||A||_2. ||A||_2 is approximated by
% largest absolute Ritz value.
% DEFAULT VALUE TOL = 1d-6
%
% OPTS.V0 A matrix of starting vectors.
% DEFAULT VALUE V0 = randn
%
% OPTS.ZERTYP Two letter string to indicate which type of zeros to apply.
% 'WL' - Weighted fast Leja points. The weight functions are used to help
% increase convergence.
% 'ML' - Mapped fast Leja points. Fast Leja points are computed on [-2,2]
% and mapped to the dampening interval. This option is not available
% when sigma is a numeric value NVAL.
% DEFAULT VALUE ZERTYP = 'ML' (If SIGMA = 'LE' or 'SE'.)
%
%
% DATE MODIFIED: 04/20/2004
% VER: 1.0
% AUTHORS:
% James Baglama University of Rhode Island, E-mail: jbaglama@math.uri.edu
% Daniela Calvetti Case Western Reserve University, E-mail: dxc57@po.cwru.edu
% Lothar Reichel Kent State University, E-mail: reichel@mcs.kent.edu
% REFERENCES:
% 1.) "IRBL: An Implicitly Restarted Block Lanczos Method for large-scale Hermitian
% eigenproblems", J. Baglama, D. Calvetti, and L. Reichel, SIAM J. Sci. Comput.,
% in press, 2003.
% 2.) "irbleigs: A MATLAB program for computing a few eigenpairs of a large sparse
% Hermitian matrix", J. Baglama, D. Calvetti, and L. Reichel, Technical Report
% submitted for publication (2001).
% 3.) "Dealing With Linear Dependence during the Iterations of the Restarted
% Block Lanczos Methods", J. Baglama, Num. Algs., 25, (2000) pp. 23-36.
% 4.) "Fast Leja Points", J. Baglama, D. Calvetti, and L. Reichel, ETNA,
% Vol. 7 (1998), pp. 124-140.
% 5.) "Computation of a few close eigenvalues of a large matrix with
% application to liquid crystal modeling", J. Baglama, D. Calvetti,
% L. Reichel, and A. Ruttan, J. of Comp. Phys., 146 (1998), pp. 203-226.
% 6.) "Iterative Methods for the Computation of a Few Eigenvalues of a Large
% Symmetric Matrix", J. Baglama, D. Calvetti, and L. Reichel, BIT, 36
% (1996), pp. 400-421.
% Values used in the GUI demo IRBLDEMO. Not needed for command line computation.
global matrixprod dnbls err output waithan;
string1 = 'plot(0.5,0.5,''Color'',[0.8 0.8 0.8]);';
string2 = 'set(gca,''XTick'',[],''YTick'',[],''Visible'',''off'');';
string3 = 'text(0,0.5,err,''FontSize'',10,''Color'',''r'');';
string4 = 'axis([0 1 0 1]);';
output = strcat(string1,string2,string3,string4);
% Too many output arguments requested.
if (nargout >= 4) error('ERROR: Too many output arguments.'); end
%----------------------------%
% BEGIN: PARSE INPUT VALUES. %
%----------------------------%
% No input arguments, return help.
if nargin == 0, help irbleigs, return, end
% Get matrix A. Check type (numeric or character) and dimensions.
if (isstruct(varargin{1}))
err = 'A must be a matrix.';
if ~isempty(gcbo), close(waithan); eval(output); end, error(err);
end
A = varargin{1};
if ischar(A)
if nargin == 1, error('Need N (size of matrix A).'); end
n = varargin{2};
if ~isnumeric(n) | length(n) > 2
error('Second argument N must be a numeric value.');
end
else
[n,n] = size(A);
if any(size(A) ~= n)
err = 'Matrix A is not square.';
if ~isempty(gcbo), close(waithan); eval(output); end, error(err);
end
if ~isnumeric(A)
err = 'A must be a numeric matrix.';
if ~isempty(gcbo), close(waithan); eval(output); end, error(err);
end
if nnz(A) == 0
err = 'Matrix A contains all zeros.';
if ~isempty(gcbo), close(waithan); eval(output); end, error(err);
end
end
% Set all input options to default values.
M = []; blsz = 3; cholM = 0; dispr = 0; eigvec = []; endpt = 'MON'; K = 3; maxdpol = 200; maxit = 100;
nbls = 3; nval = []; zertyp = 'ML'; sigma = 'LE'; sizint = 1; tol = 1d-6; V = []; permM = []; funpar = [];
% Set indicators for ENDPTS and MAXDPOL to be empty arrays. The indicators determine which
% default values should be used.
IENDPT = []; IMAXDPOL = [];
% If a generalized eigenvalue problem is to be solved get matrix M.
% Check type (numeric or character) and dimensions.
if ((ischar(A) & nargin > 2) | (isnumeric(A) & nargin > 1))
if ~isstruct(varargin{2+ischar(A)})
M = varargin{2+ischar(A)};
if ~isnumeric(M)
err = 'M must be a numeric matrix.';
if ~isempty(gcbo), close(waithan); eval(output); end, error(err);
end
if any(size(M) ~= n)
err = 'Matrix M must be the same size as A.';
if ~isempty(gcbo), close(waithan); eval(output); end, error(err);
end
end
end
% Preallocate memory for large matrices.
V = spalloc(n,nbls*blsz,n*blsz*nbls); F = spalloc(n,blsz,n*blsz);
% Get input options from the data structure.
if nargin > 1 + ischar(A) + ~isempty(M)
options = varargin{2+ischar(A) + ~isempty(M):nargin};
names = fieldnames(options);
I = strmatch('BLSZ',upper(names),'exact');
if ~isempty(I), blsz = getfield(options,names{I}); end
I = strmatch('CHOLM',upper(names),'exact');
if ~isempty(I), cholM = getfield(options,names{I}); end
I = strmatch('DISPR',upper(names),'exact');
if ~isempty(I), dispr = getfield(options,names{I}); end
I = strmatch('EIGVEC',upper(names),'exact');
if ~isempty(I), eigvec = getfield(options,names{I}); end
I = strmatch('ENDPT',upper(names),'exact'); IENDPT = I;
if ~isempty(I), endpt = upper(getfield(options,names{I})); end
I = strmatch('FUNPAR',upper(names),'exact');
if ~isempty(I), funpar = getfield(options,names{I}); end
I = strmatch('K',upper(names),'exact');
if ~isempty(I), K = getfield(options,names{I}); end
I = strmatch('MAXDPOL',upper(names),'exact'); IMAXDPOL = I;
if ~isempty(I), maxdpol = getfield(options,names{I}); end
I = strmatch('MAXIT',upper(names),'exact');
if ~isempty(I), maxit = getfield(options,names{I}); end
I = strmatch('PERMM',upper(names),'exact');
if ~isempty(I), permM = getfield(options,names{I}); end
I = strmatch('NBLS',upper(names),'exact');
if ~isempty(I), nbls = getfield(options,names{I}); end
I = strmatch('ZERTYP',upper(names),'exact');
if ~isempty(I), zertyp = upper(getfield(options,names{I})); end
I = strmatch('SIGMA',upper(names),'exact');
if ~isempty(I), sigma = upper(getfield(options,names{I})); end
I = strmatch('SIZINT',upper(names),'exact');
if ~isempty(I), sizint = getfield(options,names{I}); end
I = strmatch('TOL',upper(names),'exact');
if ~isempty(I), tol = getfield(options,names{I}); end
I = strmatch('V0',upper(names),'exact');
if ~isempty(I), V = getfield(options,names{I}); end
end
% If starting matrix V0 is not given then set starting matrix V0 to be a
% (n x blsz) matrix of normally distributed random numbers.
if nnz(V) == 0, V = randn(n,blsz); end
% Check type of input values and output error message if needed.
if (~isnumeric(blsz) | ~isnumeric(cholM) | ~isnumeric(dispr) | ~ischar(endpt) | ...
~isnumeric(K) | ~isnumeric(maxdpol) | ~isnumeric(maxit) | ~isnumeric(nbls) | ...
~ischar(zertyp) | ~isnumeric(sizint) | ~isnumeric(tol) | ~isnumeric(permM))
error('Incorrect type for input value(s) in the structure.');
end
% If a numeric value is given for sigma then set nval=sigma and sigma = 'IE' to
% denote that the code is searching for interior eigenvalues.
if isnumeric(sigma), nval = sigma; sigma = 'IE'; end
% Check the length of the character values sigma, endpt, and zertyp.
if length(sigma) ~= 2
err = 'SIGMA must be SE, LE, or a numeric value';
if ~isempty(gcbo), close(waithan); eval(output); end, error(err);
end
if length(endpt) ~= 3, error('Incorrect value for ENDPT'); end
if length(zertyp) ~= 2, error('Incorrect value for ZERTYP'); end
% Resize Krylov subspace if blsz*nbls (i.e. number of Lanczos vectors) is larger
% than n (i.e. the size of the matrix A).
if blsz*nbls >= n, nbls = floor(n/blsz); end
% Check for input errors in the data structure.
if sizint < 1, error('Incorrect value for SIZINT. SIZINT must be >= 1.'), end
if K <= 0, error('K must be a positive value.'), end
if K > n, error('K must be less than the size of A.'), end
if blsz <= 0, error('BLSZ must be a positive value.'), end
if nbls <= 1, error('NBLS must be greater than 1.'), end
if tol < 0, error('TOL must be non-negative.'), end
if maxit <= 0, error('MAXIT must be positive.'), end
if ((cholM ~= 0) & (cholM ~= 1)), error('Unknown value for cholM.'), end
if ~isempty(permM)
if ((size(permM,1) ~= n) | (size(permM,2) ~= 1)) & ...
((size(permM,1) ~= 1) | (size(permM,2) ~= n)), error('Incorrect size for PERMM'), end
end
if maxdpol < nbls, error('MAXDPOL must be >= NBLS'), end
if blsz*nbls - sizint <= blsz, error('SIZINT is too large'), end
if blsz*nbls - K - blsz - sizint < 0
nbls = ceil((K+sizint+blsz)/blsz+0.1);
warning(['Increasing NBLS to ',num2str(nbls)]);
end
if blsz*nbls >= n, error('K or SIZINT are too large.'), end
if (~strcmp(sigma,'SE') & ~strcmp(sigma,'LE') & ~strcmp(sigma,'IE'))
err = 'SIGMA must be SE, LE or a numeric value.';
if ~isempty(gcbo),close(waithan);eval(output); end, error(err);
end
if (~strcmp(endpt,'FLT') & ~strcmp(endpt,'MON')), error('Unknown value for ENDPT.'), end
if (~strcmp(zertyp,'WL') & ~strcmp(zertyp,'ML')), error('Unknown value for ZERTYP.'), end
if strcmp(sigma,'IE')
zertyp = 'WL';
if isempty(IENDPT), endpt = 'FLT'; end
if isempty(IMAXDPOL), maxdpol = n; end
end
if ~isempty(eigvec)
if ~isnumeric(eigvec), error('Incorrect type for input eigenvector(s).'), end
if ((size(eigvec,1) ~= n) | (size(eigvec,2) >= n))
error('Incorrect size of eigenvector matrix EIGVEC.');
end
end
if ~isnumeric(V), error('Incorrect starting matrix V0.'), end
if ((size(V,1) ~= n) | (size(V,2) ~= blsz)), error('Incorrect size of starting matrix V0.'), end
% Set tolerance to machine precision if tol < eps.
if tol < eps, tol = eps; end
% If a generalized eigenvalue problem is to be solved then get the Cholesky factorization
% of the matrix M (i.e. M=R'*R) and set M=R the upper triangular matrix.
if ~isempty(M)
% If M is sparse then compute the sparse cholesky factorization. Using symmmd or
% symamd to get a permutation vector permM such that M(permM,permM) will have a
% sparser cholesky factorization than M. The permutation is given by
% M(permM,permM) = I(:,permM)'*M*I(:,permM), where I is the identity matrix.
% To compute the product A(permM,permM)*x use y(permM,:) = x; y=A*y; y=y(permM,:);
% Use the default value of permM, if permM is not part of the input structure.
if isempty(permM), permM = 1:n; end
% If cholM = 1, then the input matrix M is given as R in the Cholesky factorization.
if ~cholM
[M,cholerr] = chol(M(permM,permM));
if cholerr
err = 'Matrix M must be positive definite';
if ~isempty(gcbo), close(waithan); eval(output); end, error(err);
end
end
end
%--------------------------%
% END: PARSE INPUT VALUES. %
%--------------------------%
%-----------------------------------------------------------%
% BEGIN: DESCRIPTION AND INITIALIZATION OF LOCAL VARIABLES. %
%-----------------------------------------------------------%
% Initialization and description of local variables.
conv = 0; % Number of desired eigenvalues that have converged.
deflate = 0; % Value used to determine if an undesired eigenvector has converged.
eigresdisp = []; % Holds the residual values of converged eigenvalues.
eigval = []; % Array used to hold the converged desired eigenvalues.
iter = 1; % Main loop iteration count.
fLejapts = []; % Stores fast Leja points.
lcandpts = []; % Stores "left" candidate points.
lindex = []; % Index for lcandpts.
lprd = []; % Stores the Leja polynomial product for "left" candidate points.
leftendpt = []; % Stores the left most endpoint of the dampening interval.
leftintendpt = []; % Stores the interior left endpoint of the dampening interval.
leftLejapt = []; % Place holder in fast leja routines.
mprod = 0; % The number of matrix vector products.
norlpol = []; % Normalizes the Leja polynomial to avoid underflow/overflow.
numbls = nbls; % Initial size of the Lanczos blocks.
pritz = []; % Holds previous iteration of Ritz values. Used to determine stagnation.
rcandpts = []; % Stores "right" candidate points.
rindex = []; % Index for rcandpts.
ritzconv = 'F'; % Boolean to determine if all desired eigenvalues have converged.
rprd = []; % Stores the Leja polynomial product for "right" candidate points.
rightendpt = []; % Stores the right most endpoint of the dampening interval.
rightintendpt = []; % Stores the interior right endpoint of the dampening interval.
rightLejapt = []; % Place holder in fast Leja routines.
singblk = []; % Integer values used to indicate singular block(s) in blanz.
sqrteps = sqrt(eps); % Square root of machine tolerance used in convergence testing.
flcount = 0; % Count used to determine when the maximum number of shifts is reached.
% Value use for demo only, holds the change in nbls. Not needed for command line computation.
dnbls = nbls;
% Holds the maximum absolute value of all computed Ritz values.
global Rmax; Rmax = [];
% Determine if eigenvectors are requested.
if (nargout > 1), computvec = 'T'; else computvec = 'F'; end
% Determine the number of input eigenvector(s).
if ~isempty(eigvec), ninpeigvec = size(eigvec,2); else ninpeigvec = 0; end
%--------------------------------------------------------------------%
% END: DESCRIPTION AND INITIALIZATION OF LOCAL AND GLOBAL VARIABLES. %
%--------------------------------------------------------------------%
%----------------------------%
% BEGIN: MAIN ITERATION LOOP %
%----------------------------%
while (iter <= maxit)
iter
% Check and deflate the number of Lanczos blocks if possible. Do not
% deflate if searching for interior eigenvalues or if the users has
% inputed eigenvectors. This causes nbls to increase.
if (nbls > 2 & ~strcmp(sigma,'IE') & ~ninpeigvec)
nbls = numbls - floor(size(eigvec,2)/blsz);
if (sizint >= nbls*blsz-(abs(K-size(eigvec,2))))
nbls = max(floor((sizint + abs(K-size(eigvec,2)))/blsz) + 1,numbls);
end
end
% Compute the block Lanczos decomposition.
[F,T,V,blsz,mprod,singblk] = blanz(A,K,M,permM,V,blsz,eigvec,funpar,mprod,n,nbls,singblk,sqrteps,tol);
% Determine number of blocks and size of the block tridiagonal matrix T.
Tsz = size(T,1); nbls = Tsz/blsz;
if (floor(nbls) ~= nbls)
% Reset the starting matrix V and re-compute the block Lanczos decomposition if needed.
[F,T,V,blsz,mprod,singblk] = blanz(A,K,M,permM,randn(n,blsz),blsz,eigvec,mprod,n,nbls,singblk,sqrteps,tol);
Tsz = size(T,1); nbls = Tsz/blsz;
if floor(nbls) ~= nbls
err='blanz in irbleigs.m returns an incorrect matrix T.';
if ~isempty(gcbo), close(waithan); eval(output); end, error(err);
end
end
% Compute eigenvalues and eigenvectors of the block tridiagonal matrix T.
[ritzvec,ritz] = eig(T); ritz = diag(ritz);
% Sort the eigenvalues from smallest to largest.
[ritz,J] = sort(real(ritz)); ritzvec = ritzvec(:,J);
% Reached maximum number of iterations, exit main loop.
if iter >= maxit, break, end;
% Compute the residuals for all ritz values.
residuals = sqrt(sum((F*ritzvec(Tsz-(blsz-1):Tsz,:)).*(F*ritzvec(Tsz-(blsz-1):Tsz,:))));
% Convergence tests.
[conv,deflate,eigval,eigvec,eigresdisp,pritz,ritzconv,singblk] = ...
convtests(computvec,conv,deflate,dispr,eigval,eigvec,eigresdisp,...
iter,K,nval,pritz,residuals,ritz,ritzconv,ritzvec,sigma,...
singblk,sqrteps,tol,Tsz,V);
% If all desired Ritz values converged then exit main loop.
if strcmp(ritzconv,'T'), break, end;
% Determine dampening intervals, Leja points, and apply Leja zeros as shifts.
[fLejapts,lcandpts,leftendpt,leftintendpt,lprd,leftLejapt,lindex,maxdpol,nbls,norlpol,nval,...
rcandpts,rightendpt,rightintendpt,rprd,rightLejapt,rindex,V,flcount] = ...
applyshifts(blsz,endpt,F,fLejapts,iter,K,lcandpts,leftendpt,leftintendpt,...
lprd,leftLejapt,lindex,maxdpol,nbls,norlpol,nval,rcandpts,...
rightendpt,rightintendpt,ritz,ritzvec,rprd,rightLejapt,rindex,...
zertyp,sigma,singblk,sizint,sqrteps,Tsz,T,V,flcount);
% Check to see if an undesired Ritz vector has been chosen to be deflated. If so,
% reset the endpoints of the dampening interval(s) on the next interation.
if deflate
deflate = 0; Rmax = []; leftintendpt = []; rightintendpt = []; leftendpt = []; rightendpt = [];
end
% Update the main iteration loop count.
iter = iter + 1;
% Wait bar used in the GUI demo IRBLDEMO. Not used for command line computation.
if ~isempty(gcbo), waitbar(iter/maxit), end
end % While loop.
%--------------------------%
% END: MAIN ITERATION LOOP %
%--------------------------%
%-----------------------%
% BEGIN: OUTPUT RESULTS %
%-----------------------%
% Test to see if maximum number of iterations is reached.
% If output options 1 or 2 are used then set eigval and
% eigvec to be empty arrays.
% If output option 4 is used then use the last Ritz
% pairs as estimate for the unconverged eigenpairs.
PRGINF(1) = 0;
if iter >= maxit & nargout <= 2
PRGINF(1) = 1; eigval = []; eigvec = [];
end
if iter >= maxit & nargout == 3
PRGINF(1) = 1;
NC = K - length(eigval);
if strcmp(sigma,'SE'), JI = 1:NC; end
if strcmp(sigma,'LE'), JI = Tsz-NC+1:Tsz; end
if strcmp(sigma,'IE'), [sortval,JI] = sort(abs(ritz-nval)); end
eigval = [eigval;ritz(JI(1:NC))];
eigvec = [eigvec,V*ritzvec(:,JI(1:NC))];
end
% Sort output arguments.
if ~isempty(eigval)
K = min(length(eigval),K); eigval = real(eigval);
if strcmp(sigma,'SE'), [sortval,I] = sort(eigval); I = I(1:K); end
if strcmp(sigma,'LE')
[sortval,I] = sort(eigval); I = flipud(I); I = I(1:K);
end
if strcmp(sigma,'IE')
[sortval,I] = sort(abs(eigval-nval)); I = I(1:K);
[sortval,J] = sort(eigval(I)); I = I(J);
end
eigval = eigval(I);
end
% Output option I: Display eigenvalues only.
if (nargout == 0), eigenvalues = eigval, end
% Output option II: Set eigenvalues equal to output vector.
if (nargout == 1),varargout{1} = eigval; end
% Output option III and IV: Output diagonal matrix of eigenvalues and
% corresponding matrix of eigenvectors.
if ((nargout == 2) | (nargout == 3))
if ~isempty(eigvec)
eigvec = eigvec(:,ninpeigvec+1:size(eigvec,2));
eigvec = eigvec(:,I);
% Must solve a linear system to extract generalized eigenvectors.
if ~isempty(M)
eigvec = M\eigvec(permM,:);
end
else
eigvec = [];
end
varargout{1} = eigvec;
varargout{2} = diag(eigval);
end
% Output option IV: Output PRGINF.
if nargout == 3, PRGINF(2) = mprod; varargout{3} = PRGINF; end
% Used in the GUI demo IRBLDEMO. Not used for command line computation.
% Outputs number of matrix-vector products.
matrixprod = mprod;
%---------------------%
% END: OUTPUT RESULTS %
%---------------------%
%------------------------------------%
% BEGIN: BLOCK LANCZOS DECOMPOSITION %
%------------------------------------%
function [F,T,V,blsz,mprod,singblk] = blanz(A,K,R,permM,V,blsz,eigvec,funpar,mprod,n,nbls,singblk,sqrteps,tol)
% Computes the Block Lanczos decomposition, A*V = V*T + F*E^T
% with full reorthogonalization. If the generalized eigenvalue
% problem A*x = lambda*M*x is to be solved then M=R'*R and the
% Lanczos decomposition, inv(R')*A*inv(R)*V = V*T + F*E^T is returned.
%
% The matrix A can be passed as a numeric matrix or as a filename.
% However, the matrix M must be passed as a numeric matrix. Note that
% if the matrix A is a filename then the file must accept
% [X(n,blsz),n,blsz] or [X(n,blsz),n,blsz,funpar] as input in that
% order and the file must return the matrix product A*X(n,blsz).
% James Baglama
% DATE: 11/06/01
% Values used in the GUI demo IRBLDEMO. Not needed for command line computation.
global err output waithan;
% Initialization of residual matrix F, main loop count J, and integer singblk.
F=zeros(n,blsz); J = 1; singblk = []; singblk(1) = 0;
% Check size of input vectors V and eigvec for errors.
if (size(V,1) ~= n | blsz < 1)
err = 'Incorrect size of starting vectors, V in blanz.';
if ~isempty(gcbo), close(waithan); eval(output); end, error(err);
end
if size(V,2) ~= blsz, blsz = size(V,2); end
if ~isempty(eigvec)
if size(eigvec,1) ~= n
err = 'Incorrect size of EIGVEC in blanz.';
if ~isempty(gcbo),close(waithan); eval(output); end, error(err);
end
end
% First orthogonalization of starting vectors.
V = orth(V);
% Orthogonalize V against all converged eigenvectors.
if ~isempty(eigvec)
if size(eigvec,2) < size(V,2)
V = V - eigvec*(eigvec'*V); doteV = eigvec'*V;
else
V = V - eigvec*(V'*eigvec)'; doteV = (V'*eigvec)';
end
if norm(doteV) > sqrteps, V = V - eigvec*doteV; end
end
% First check of linear dependence of starting vector(s). If starting vector(s)
% are linearly dependent then add normalized random vectors and reorthogonalize.
if rank(V,sqrteps*n*blsz) < blsz
V = V + randn(n,blsz); V = orth(V);
if ~isempty(eigvec)
if size(eigvec,2) < size(V,2)
V = V - eigvec*(eigvec'*V); doteV = eigvec'*V;
else
V = V - eigvec*(V'*eigvec)'; doteV = (V'*eigvec)';
end
if norm(doteV) > sqrteps, V = V - eigvec*doteV; end
end
end
% If needed second orthogonalization of starting vectors.
if ~isempty(eigvec), V = orth(V); end
% Second check of linear dependence of starting vector(s). If starting vector(s)
% are linearly dependent then add normalized random vectors and reorthogonalize.
if (size(V,2) < blsz)
V = [V,randn(n,blsz-size(V,2))];
if ~isempty(eigvec)
if size(eigvec,2) < size(V,2)
V = V - eigvec*(eigvec'*V); doteV = eigvec'*V;
else
V = V - eigvec*(V'*eigvec)'; doteV = (V'*eigvec)';
end
if norm(doteV) > sqrteps, V = V - eigvec*doteV; end
end
% If needed third orthogonalization of starting vectors.
V = orth(V);
% Third check of linear dependence of starting vector(s). If starting vector(s)
% are linearly dependent fatal error return.
if (size(V,2) < blsz)
err = 'Dependent starting vectors in block Lanczos.';
if ~isempty(gcbo), close(waithan); eval(output); end, error(err);
end
end
% Check desired size of Lanczos matrix T. If size is greater than n
% reduce size to the next multiple of blsz that is less than n.
if blsz*nbls >= n, nbls = floor(n/blsz); end
% Begin of main iteration loop for the block Lanczos decomposition.
while (J <= nbls)
% Values used for indices.
Jblsz = J*blsz; Jm1blszp1 = blsz*(J-1)+1;
% Matrix product with vector(s).
if ~isempty(R)
% Generalized eigenvalue problem.
F(permM,:) = R \ V(:,Jm1blszp1:Jblsz);
if ischar(A)
if isempty(funpar)
F = feval(A,F,n,blsz);
else
F = feval(A,F,n,blsz,funpar);
end
else
F = A*F;
end
F = (F(permM,:)'/R)';
else
% Standard eigenvalue problem.
if ischar(A)
if isempty(funpar)
F = feval(A,V(:,Jm1blszp1:Jblsz),n,blsz);
else
F = feval(A,V(:,Jm1blszp1:Jblsz),n,blsz,funpar);
end
else
F = A*V(:,Jm1blszp1:Jblsz);
end
end
% Count the number of matrix vector products.
mprod = mprod + blsz;
% Orthogonalize F against the previous Lanczos vectors.
if (J > 1)
F = F - V(:,blsz*(J-2)+1:Jm1blszp1-1)*...
T(Jm1blszp1:Jblsz,blsz*(J-2)+1:Jm1blszp1-1)';
end
% Compute the diagonal block of T.
D = F'*V(:,Jm1blszp1:Jblsz);
% One step of the block classical Gram-Schmidt process.
F = F - V(:,Jm1blszp1:Jblsz)*D;
% Full reorthogonalization step.
dotFV = (F'*V)'; F = F - V*dotFV;
if norm(dotFV)>sqrteps, dotFV2 = (F'*V)'; dotFV=dotFV+dotFV2; F = F - V*dotFV2; end
for i = 1:J, D = D + dotFV(blsz*(i-1)+1:blsz*i,:); end
% Orthogonalize F against all converged eigenvectors.
if ~isempty(eigvec)
if size(eigvec,2) < size(F,2)
F = F - eigvec*(eigvec'*F); doteF = eigvec'*F;
else
F = F - eigvec*(F'*eigvec)'; doteF = (F'*eigvec)';
end
if norm(doteF) > sqrteps, F = F - eigvec*doteF; end
end
% To ensure a symmetric matrix T is computed.
T(Jm1blszp1:Jblsz,Jm1blszp1:Jblsz) = tril(D,-1) + tril(D)';
% Compute QR factorization and off diagonal block of T.
if (J < nbls)
[V(:,Jblsz+1:blsz*(J+1)),T(Jblsz+1:blsz*(J+1),Jm1blszp1:Jblsz)] = qr(F,0);
% Check for linearly dependent vectors among the blocks.
stol = max(min(sqrteps,tol),eps*max(abs(diag((T(Jblsz+1:blsz*(J+1),Jm1blszp1:Jblsz))))));
I = find(abs(diag(T(Jblsz+1:blsz*(J+1),Jm1blszp1:Jblsz))) <= stol);
% Linearly dependent vectors detected in the current block.
if ~isempty(I)
% Exit. Convergence or not enough vectors to continue to build up the space.
if ~isempty(eigvec), sizevec = size(eigvec,2); else sizevec = 0; end
if (((size(I,1) == blsz) & (size(T,2) >= K)) | (sizevec + size(T,2) >= n))
% Resize T and V and exit.
T = T(1:size(T,2),1:size(T,2)); V = V(:,1:size(T,2)); return;
end
% Full Reorthogonalization step to ensure orthogonal vectors.
V = V(:,1:Jblsz);
dotFV = (F'*V)'; F = F - V*dotFV;
if norm(dotFV) > sqrteps, dotFV2 = (F'*V)'; dotFV = dotFV+dotFV2; F = F - V*dotFV2; end
for i = 1:J
T(Jm1blszp1:Jblsz,Jm1blszp1:Jblsz) = ...
T(Jm1blszp1:Jblsz,Jm1blszp1:Jblsz) + ...
dotFV(blsz*(i-1)+1:blsz*i,:);
end
% Orthogonalize F against all converged eigenvectors.
if ~isempty(eigvec)
if size(eigvec,2) < size(F,2)
F = F - eigvec*(eigvec'*F); doteF = eigvec'*F;
else
F = F - eigvec*(F'*eigvec)'; doteF = (F'*eigvec)';
end
if norm(doteF) > sqrteps, F = F - eigvec*doteF; end
end
% To ensure a symmetric matrix T is computed.
T(Jm1blszp1:Jblsz,Jm1blszp1:Jblsz) = tril(T(Jm1blszp1:Jblsz,Jm1blszp1...
:Jblsz),-1)+tril(T(Jm1blszp1:Jblsz,Jm1blszp1:Jblsz))';
% Re-compute QR with random vectors.
[V(:,Jblsz+1:blsz*(J+1)),T(Jblsz+1:blsz*(J+1),Jm1blszp1:Jblsz)] = ...
qrsingblk(F,V(:,1:Jblsz),eigvec,I,blsz,sqrteps);
% Set the singular block indicator to true along with which vector(s)
% are linearly dependent.
singblk(1) = 1; singblk = [singblk,Jblsz+I'];
end
% Set off diagonal blocks to be equal.
T(Jm1blszp1:Jblsz,Jblsz+1:blsz*(J+1)) = T(Jblsz+1:blsz*(J+1),Jm1blszp1:Jblsz)';
end
% Update iteration count (block Lanczos while loop).
J = J + 1;
end % While loop.
function [F,R] = qrsingblk(F,V,eigvec,I,blsz,sqrteps)
% This function computes the QR factorization for a singular
% off diagonal block of the block tridiagonal matrix T.
% The diagonal element R(k,k) of R associated with the linearly
% dependent vector F(:,k) is set to zero and F(:,k) is set to a
% random vector that is orthogonal to previous Lanczos vectors
% and any converged eigenvectors.
% James Baglama
% DATE: 11/06/01
% Initialize off-diagonal block to zero.
R = zeros(blsz,blsz); n = size(F,1);
for k = 1 : blsz
if ~all(I-k)
% Set F(:,k) to a random vector and orthogonalizes F(:,k) to
% all previous Lanczos vectors and any converged eigenvectors.
F(:,k) = randn(n,1);
dotVF = V'*F(:,k); F(:,k) = F(:,k) - V*dotVF;
if k > 1, dotVF = F(:,1:k-1)'*F(:,k); F(:,k) = F(:,k) - F(:,1:k-1)*dotVF; end
% Iterative refinement.
dotVF = V'*F(:,k); F(:,k) = F(:,k) - V*dotVF;
if k > 1, dotVF = F(:,1:k-1)'*F(:,k); F(:,k) = F(:,k) - F(:,1:k-1)*dotVF; end
% Orthogonalize F(:,k) against all converged eigenvectors.
if ~isempty(eigvec)
F(:,k) = F(:,k) - eigvec*(F(:,k)'*eigvec)'; doteF = (F(:,k)'*eigvec)';
if norm(doteF) > sqrteps, F(:,k) = F(:,k) - eigvec*doteF; end
end
F(:,k) = F(:,k)/norm(F(:,k));
% Set diagonal element to zero.
R(k,k) = 0;
else
R(k,k) = norm(F(:,k));
F(:,k) = F(:,k) / R(k,k);
end
% Modified Gram-Schmidt orthogonalization.
for j = k+1:blsz
R(k,j) = F(:,k)' * F(:,j);
F(:,j) = F(:,j) - R(k,j) * F(:,k);
end
% Iterative refinement
for j = k+1:blsz
dotFF = F(:,k)' * F(:,j);
R(k,j) = R(k,j) + dotFF;
F(:,j) = F(:,j) - dotFF * F(:,k);
end
end
%----------------------------------%
% END: BLOCK LANCZOS DECOMPOSITION %
%----------------------------------%
%--------------------------%
% BEGIN: CONVERGENCE TESTS %
%--------------------------%
function [conv,deflate,eigval,eigvec,eigresdisp,pritz,ritzconv,singblk] = ...
convtests(computvec,conv,deflate,dispr,eigval,eigvec,eigresdisp,...
iter,K,nval,pritz,residuals,ritz,ritzconv,ritzvec,sigma,...
singblk,sqrteps,tol,Tsz,V)
% This function checks the convergence of Ritz values and Ritz vectors.
% James Baglama
% DATE: 11/06/01
global Rmax;
% Initialization of local variables.
dif = []; % Place holder for the difference of sets Jr(Jre) and Jrv(Jrev).
Jr = []; % Place holder for which Ritz values converged.
Jre = []; % Place holder for which desired Ritz values onverged.
Jrv = []; % Place holder for which Ritz vectors converged.
Jrev = []; % Place holder for which desired Ritz vectors converged.
ST = []; % Place holder for which Ritz values stagnated.
% Compute maximum Ritz value to estimate ||A||_2.
if isempty(Rmax)
Rmax = abs(ritz(Tsz));
else
Rmax = max(Rmax,abs(ritz(Tsz)));
end
Rmax = max(eps^(2/3),Rmax);
% Compute tolerance to determine when a Ritz Vector has converged.
RVTol = min(sqrteps,tol);
% Check for stagnation of Ritz values. eps*100 is used for a tolerance
% to determine when the desired Ritz values are stagnating.
if iter > 1
if length(pritz) == length(ritz)
ST = find(abs(pritz-ritz) < eps*100);
end
end
% Check for convergence of Ritz values and vectors.
switch sigma
% Smallest eigenvalues.
case 'SE'
% Check for convergence of Ritz vectors.
Jrv = find(residuals < RVTol*Rmax);
Jrev = find(Jrv <= K-conv);
% Check for convergence of Ritz values.
Jr = union(find(residuals < tol*Rmax),ST);
Jre = find(Jr <= K-conv);
% Output intermediate results.
if dispr ~= 0
dispeig = [eigval;ritz(1:K-conv)];
disperr = [eigresdisp';residuals(1:K-conv)'];
[sortval,JI] = sort(dispeig); dispeig = dispeig(JI); disperr = disperr(JI);
dispeig = dispeig(1:K); disperr = disperr(1:K);
disp(sprintf(' Ritz Residual Iteration: %d',iter));
S = sprintf('%15.5e %15.5e \n',[dispeig';disperr']);
disp(S); disp(' '); disp(' ');
end
% Largest eigenvalues.
case 'LE'
% Check for convergence of Ritz vectors.
Jrv = find(residuals < RVTol*Rmax);
Jrev = find(Jrv >= Tsz-K+1+conv);
% Check for convergence of Ritz values.
Jr = union(find(residuals < tol*Rmax),ST);
Jre = find(Jr >= Tsz-K+1+conv);
% Output intermediate results.
if dispr ~= 0
dispeig = [eigval;ritz(Tsz-K+1+conv:Tsz)];
disperr = [eigresdisp';residuals(Tsz-K+1+conv:Tsz)'];
[sortval,JI] = sort(dispeig); dispeig = dispeig(JI); disperr = disperr(JI);
dispeig = dispeig(length(dispeig)-K+1:length(dispeig));
disperr = disperr(length(dispeig)-K+1:length(dispeig));
disp(sprintf(' Ritz Residual Iteration: %d',iter));
S = sprintf('%15.5e %15.5e \n',[dispeig';disperr']);
disp(S); disp(' '); disp(' ');
end
% Eigenvalues near nval.
case 'IE'
% Determine a window where the desired Ritz values will occur.
[sortval,JI] = sort(abs(ritz-nval));
ritz = ritz(JI); ritzvec = ritzvec(:,JI);
residuals = residuals(JI);
% Check for convergence of Ritz vectors.
Jrv = find(residuals < RVTol*Rmax);
Jrev = find(Jrv <= K-conv);
% Check for convergence of Ritz values.
Jr = union(find(residuals < tol*Rmax),ST);
Jre = find(Jr <= K-conv);
% Output intermediate results.
if dispr ~= 0
% Sort output values.
[sortval,JI] = sort(ritz(1:K-conv));
sritz = ritz(1:K-conv); sresiduals =residuals(1:K-conv);
sritz = sritz(JI); sresiduals = sresiduals(JI);
dispeig = [eigval;sritz];
disperr = [eigresdisp';sresiduals'];
[sortval,JI] = sort(dispeig); dispeig = dispeig(JI); disperr = disperr(JI);
dispeig = dispeig(1:K); disperr = disperr(1:K);
disp(sprintf(' Ritz Residual Iteration: %d',iter));
S = sprintf('%15.5e %15.5e \n',[dispeig';disperr']);
disp(S); disp(' '); disp(' ');
end
end % Switch sigma.
% Remove common values in Jre and Jrev. Common values indicate a desired
% Ritz pair has converged and will be deflated.
if ~isempty(Jr(Jre))
dif = setdiff(Jr(Jre),Jrv(Jrev));
end
% Determine the number of converged desired Ritz vectors.
conv = conv + length(Jrev);
% Determine if the requested number of desired Ritz values have converged.
if conv+length(dif) >= K
eigval = [eigval;ritz(union(Jr(Jre),Jrv(Jrev)))];
% If eigenvectors are requested then compute eigenvectors.
if strcmp(computvec,'T')
if isempty(eigvec)