-
Notifications
You must be signed in to change notification settings - Fork 2
/
675
7403 lines (6654 loc) · 229 KB
/
675
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
C ALGORITHM 675, COLLECTED ALGORITHMS FROM ACM.
C THIS WORK PUBLISHED IN TRANSACTIONS ON MATHEMATICAL SOFTWARE,
C VOL. 15, NO. 3, PP. 243-256.
C
C This is the driver for SUBROUTINE SRCF.
C The routine is in TOMS.FOR and uses the file SRCF.IN as
C input file from which N, P, A, B, C, R and Q are read.
C Output is sent to file SRCF.OUT .
C
INTEGER I, ISTEP, J, N, M, P, LDS, LDA, LDB, LDQ, LDC, LDR, LDK,
* LDW
DOUBLE PRECISION A(10,10), B(10,5), C(7,10), R(7,7), Q(5,5),
* WRK(22,22), S(10,10), K(10,7),
* SSP(10,10)
DOUBLE PRECISION DDOT, TOL
LOGICAL MULTBQ, WITHK
C
WITHK = .TRUE.
MULTBQ = .TRUE.
LDS = 10
LDA = 10
LDB = 10
LDQ = 5
LDC = 7
LDR = 7
LDK = 10
LDW = 22
TOL = 1.D-15
C
C READ N, P, A, B, C, Q and R from the file SRCF.IN
C The matrices A, B, C, Q and R are to be read columnwise.
C The input dimension M is specified by the loop index.
C
C
REWIND 1
DO 750 M = 2, 3
READ (1,51) N, P
51 FORMAT(2I5)
53 FORMAT(1H ,'*** N =', I3, ' M =', I3,' P = ', I3)
IF (M .EQ. 2) THEN
WRITE(2,940)
ELSE
WRITE(2,941)
END IF
DO 50 J = 1, N
DO 50 I = 1, N
READ(1,52) A(I,J)
50 CONTINUE
52 FORMAT(D25.15)
DO 60 J = 1, M
DO 60 I = 1, N
READ(1,52) B(I,J)
60 CONTINUE
DO 68 J = 1, N
DO 68 I = 1, P
READ(1,52) C(I,J)
68 CONTINUE
DO 76 J = 1, P
DO 76 I = 1, P
READ(1,52) R(I,J)
76 CONTINUE
DO 84 J = 1, M
DO 84 I = 1, M
READ(1,52) Q(I,J)
84 CONTINUE
C
C Initialize the S matrix to be the null matrix.
C
DO 350 J = 1, N
DO 350 I = 1, N
S(I,J) = 0.0D0
350 CONTINUE
WRITE(2,950)
WRITE(2,53) N, M, P
CALL PRMT(A,LDA,N,N,'A matrix',2,4)
CALL PRMT(B,LDB,N,M,'B matrix',2,4)
CALL PRMT(S,LDS,N,N,'S matrix',2,4)
CALL PRMT(C,LDC,P,N,'C matrix',2,4)
CALL PRMT(R,LDR,P,P,'R matrix',2,4)
CALL PRMT(Q,LDQ,M,M,'Q matrix',2,4)
C
C Now perform three steps of the Kalman filter recursion
C (in square root covariance form) with MULTBQ = .TRUE.
C
WRITE(2,951)
DO 500 ISTEP = 1, 3
WRITE(2,935)ISTEP
CALL SRCF(S, LDS, A, LDA, B, LDB, Q, LDQ, C, LDC, R, LDR,
* N, M, P, K, LDK, WRK, LDW, MULTBQ, WITHK, TOL)
CALL PRMT(S,LDS,N,N,'S matrix',2,4)
CALL PRMT(K,LDK,N,P,'K matrix',2,4)
DO 450 J = 1, N
DO 450 I = 1, N
SSP(I,J) = DDOT(N, S(I,1), LDS, S(J,1), LDS)
450 CONTINUE
CALL PRMT(SSP,LDS,N,N,'SS'' m. ',2,4)
500 CONTINUE
WRITE(2,952)
C
C Initialize the S matrix to be the null matrix.
C
DO 550 J = 1, N
DO 550 I = 1, N
S(I,J) = 0.0D0
550 CONTINUE
C
C Now perform three steps of the Kalman filter recursion
C (in square root covariance form) with MULTBQ = .FALSE.
C
MULTBQ = .FALSE.
DO 700 ISTEP = 1, 3
WRITE(2,935)ISTEP
CALL SRCF(S, LDS, A, LDA, B, LDB, Q, LDQ, C, LDC, R, LDR,
* N, M, P, K, LDK, WRK, LDW, MULTBQ, WITHK, TOL)
CALL PRMT(S,LDS,N,N,'S matrix',2,4)
CALL PRMT(K,LDK,N,P,'K matrix',2,4)
DO 650 J = 1, N
DO 650 I = 1, N
SSP(I,J) = DDOT(N, S(I,1), LDS, S(J,1), LDS)
650 CONTINUE
CALL PRMT(SSP,LDS,N,N,'SS'' m. ',2,4)
700 CONTINUE
IF (M .EQ. 2) THEN
WRITE(2,945)
ELSE
WRITE(2,946)
END IF
750 CONTINUE
935 FORMAT(' *** ISTEP =', I3)
940 FORMAT(
* ' *** First example : Square root covariance filter with dense'/
* ' *** A, B, C and lower triangular Q, R.')
941 FORMAT(
* '1*** Second example : Square root covariance filter with dense'/
* ' *** A, B, C and lower triangular Q, R.')
945 FORMAT(
* '1*** In both these tests we start with S=0 and perform three'/
* ' *** iterations of the filter.'/
* ' *** The ranks of S in these three steps must be equal to '/
* ' *** M(=2), 2M(=4) and 3M(=6).'/
* ' *** K must be 0 in the first step and nonzero afterwards.'/
* ' *** The results for MULTBQ = .TRUE. and .FALSE. must be equal'/
* ' *** since we chose Q=I.'/
* ' *** The SS'' matrices are meant for comparison with SRCFOB.')
946 FORMAT(
* '1*** In both these tests we start with S=0 and perform three'/
* ' *** iterations of the filter.'/
* ' *** The ranks of S in these three steps must be equal to '/
* ' *** M(=3), 2M(=6) and min(N,3M)(=6).'/
* ' *** K must be 0 in the first step and nonzero afterwards.'/
* ' *** The results for MULTBQ = .TRUE. and .FALSE. must be equal'/
* ' *** since we chose Q=I.'/
* ' *** The SS'' matrices are meant for comparison with SRCFOB.')
950 FORMAT(// ' *** Input SRCF' //)
951 FORMAT(// ' *** Output SRCF for MULTBQ=.TRUE.' //)
952 FORMAT(// ' *** Output SRCF for MULTBQ=.FALSE.' //)
C
C *** Last line of SRCF/MAIN ******************************************
C
END
C
C This is the driver for SUBROUTINE SRIF.
C The routine is in TOMS.FOR and uses the file SRIF.IN as
C input file from which N, M, Ainv, C, AinvB, Qinv, Rinv, Z, X
C and Y are read. Output is sent to file SRIF.OUT .
C
INTEGER I, ISTEP, J, N, M, P, LDS, LDA, LDB, LDQ, LDC, LDR, LDW,
* NMP
DOUBLE PRECISION AINV(10,10), C(5,10), RINV(5,5), QINV(7,7)
DOUBLE PRECISION WRK(22,22), SINV(10,10), Y(5)
DOUBLE PRECISION SPS(10,10), Z(7), X(10)
DOUBLE PRECISION AINVB(10,7), RINVY(5)
DOUBLE PRECISION DDOT, TOL
LOGICAL MULTAB, MULTRC, WITHX
C
WITHX = .TRUE.
MULTAB = .TRUE.
MULTRC = .FALSE.
LDS = 10
LDA = 10
LDB = 10
LDQ = 7
LDC = 5
LDR = 5
LDW = 22
TOL = 1.D-15
C
C READ N, M, Ainv, C, AinvB, Qinv, Rinv, Z, X and Y from the file
C SRIF.IN. The matrices Ainv, C, AinvB, Qinv and Rinv are to be
C read columnwise.
C The input dimension P is specified by the loop index.
C
REWIND 1
DO 750 P = 2, 3
READ (1,51) N, M
NMP = N + M + P
IF (LDW .LT. NMP) WRITE(6,901)
51 FORMAT(2I5)
53 FORMAT(1H ,'*** N =', I3,' M =', I3,' P = ', I3)
IF (P .EQ. 2) THEN
WRITE(2,940)
ELSE
WRITE(2,941)
END IF
DO 50 J = 1, N
DO 50 I = 1, N
READ(1,52) AINV(J,I)
50 CONTINUE
52 FORMAT(D25.15)
DO 60 J = 1, P
DO 60 I = 1, N
READ(1,52) C(J,I)
60 CONTINUE
DO 68 I = 1, M
DO 68 J = 1, N
READ(1,52) AINVB(J,I)
68 CONTINUE
DO 76 J = 1, M
DO 76 I = 1, M
READ(1,52) QINV(J,I)
76 CONTINUE
DO 81 J = 1, P
DO 81 I = 1, P
READ(1,52) RINV(J,I)
81 CONTINUE
DO 86 J = 1, M
READ(1,52) Z(J)
86 CONTINUE
DO 88 J = 1, N
READ(1,52) X(J)
88 CONTINUE
DO 90 J = 1, P
READ(1,52) Y(J)
90 CONTINUE
C
C Initialize the SINV matrix to be the unit matrix.
C
DO 100 J = 1, N
DO 100 I = 1, N
SINV(I,J) = 0.0D0
100 CONTINUE
DO 110 I = 1, N
SINV(I,I) = 1.0D0
110 CONTINUE
WRITE(2,950)
WRITE(2,53) N, M, P
CALL PRMT(AINV,LDA,N,N,'Ainv ',2,4)
CALL PRMT(AINVB,LDA,N,M,'AinvB ',2,4)
CALL PRMT(C,LDC,P,N,'C matrix',2,4)
CALL PRMT(SINV,LDS,N,N,'Sinv ',2,4)
CALL PRMT(QINV,LDQ,M,M,'Qinv ',2,4)
CALL PRMT(RINV,LDR,P,P,'Rinv ',2,4)
CALL PRMT(Z,LDQ,M,1,'Z vector',2,4)
CALL PRMT(X,LDA,N,1,'X vector',2,4)
CALL PRMT(Y,LDC,P,1,'Y vector',2,4)
C
C Calculation of RINV x Y.
C
DO 260 I = 1, P
RINVY(I) = DDOT(P, RINV(I,1), LDR, Y, 1)
260 CONTINUE
C
C Now perform four steps of the Kalman filter recursion
C (in square root covariance form).
C
WRITE(2,951)
DO 500 ISTEP = 1, 4
WRITE(2,935)ISTEP
CALL SRIF(SINV, LDS, AINV, LDA, AINVB, LDB, RINV, LDR, C,
* LDC, QINV, LDQ, X, RINVY, Z, N, M, P, WRK, LDW,
* MULTAB, MULTRC, WITHX, TOL)
CALL PRMT(SINV,LDS,N,N,'Sinv ',2,4)
CALL PRMT(X,LDA,N,1,'X vector',2,4)
DO 450 J = 1, N
DO 450 I = 1, N
SPS(I,J) = DDOT(N, SINV(1,I), 1, SINV(1,J), 1)
450 CONTINUE
CALL PRMT(SPS,LDS,N,N,'Sin''Sin',2,4)
500 CONTINUE
IF (P .EQ. 2) THEN
WRITE(2,945)
ELSE
WRITE(2,946)
END IF
750 CONTINUE
C
900 FORMAT(' ', 8(D12.6,1X), D12.6)
901 FORMAT(' *********** Dimensions of WRK are less than N+M+P ')
935 FORMAT(' *** ISTEP =', I3)
940 FORMAT(
* '1*** First example : Square root information filter with'/
* ' *** dense A, B, C and upper triangular Q, R. ***')
941 FORMAT(
* '1*** Second example : Square root information filter with'/
* ' *** dense A, B, C and upper triangular Q, R. ***')
945 FORMAT(
* '1*** In both these tests we start with Sinv=I and perform'/
* ' *** four iterations of the filter.'/
* ' *** The Sinv''Sinv matrices and X vectors are meant for '/
* ' *** comparison with SRIFCO.')
946 FORMAT(
* '1*** In both these tests we start with Sinv=I and perform'/
* ' *** four iterations of the filter.'/
* ' *** The Sinv''Sinv matrices and X vectors are meant for '/
* ' *** comparison with SRIFCO.')
950 FORMAT(// ' *** Input SRIF' //)
951 FORMAT(// ' *** Output SRIF' //)
C
C *** Last line of the program SRIF ***********************************
C
END
C
C This is the driver for SUBROUTINE OBHESS.
C The routine is in TOMS.FOR and uses the file OBHESS.IN as
C input file from which N, UPPER, TOL, A and B are read.
C Output is sent to file OBHESS.OUT .
C
C .. Local Scalars ..
DOUBLE PRECISION SCALE,SUMSQ,TOL
INTEGER I,J,LDA,LDB,LDU,M,N
LOGICAL UPPER,WITHU
C ..
C .. Local Arrays ..
DOUBLE PRECISION A(10,10),A0(10,10),B(5,10),B0(5,10),U(10,10),
* WORK(10)
C ..
C .. External Subroutines ..
EXTERNAL DCOPY,DGEMV,OBHESS,F06FBF,F06FJF
C ..
C .. Intrinsic Functions ..
INTRINSIC DSQRT
C ..
WITHU = .TRUE.
LDA = 10
LDB = 5
LDU = 10
C
C READ N, UPPER, TOL, A and B from file OBHESS.IN
C The matrices A and B are to be read column by column.
C The input dimension M is specified by the loop index.
C
REWIND 1
READ (1,FMT='()')
DO 700 M = 2,3
READ (1,FMT=15) N,UPPER,TOL
15 FORMAT (I5,L5,D11.1)
17 FORMAT (1H ,'*** N =',I3,' M =',I3,' UPPER = ',L3,' TOL =',
* D8.1)
IF (M.EQ.2) THEN
WRITE (2,FMT=940)
ELSE
WRITE (2,FMT=941)
END IF
C
C The matrices A and B are read, and also stored in A0 and B0 for
C later use.
C
READ (1,FMT=52) ((A(I,J),I=1, N),J=1, N)
DO 51 J = 1,N
CALL DCOPY(N,A(1,J),1,A0(1,J),1)
51 CONTINUE
52 FORMAT (D25.15)
READ (1,FMT=52) ((B(I,J),I=1, M),J=1, N)
DO 61 J = 1,N
CALL DCOPY(M,B(1,J),1,B0(1,J),1)
61 CONTINUE
C
C The matrix U is initialized as the identity matrix.
C
DO 100 J = 1,N
DO 90 I = 1,N
U(I,J) = 0.D0
90 CONTINUE
U(J,J) = 1.D0
100 CONTINUE
WRITE (2,FMT=950)
WRITE (2,FMT=17) N,M,UPPER,TOL
CALL PRMT(A0,LDA,N,N,'A0 matr. ',2,4)
CALL PRMT(B0,LDB,M,N,'B0 matr. ',2,4)
C
C Calling the controller Hessenberg form routine.
C
CALL OBHESS(A,LDA,N,B,LDB,M,U,LDU,WITHU,UPPER)
C
C The transformed matrices A and B, and the transformation matrix U
C are output.
C
WRITE (2,FMT=951)
CALL PRMT(A,LDA,N,N,'A matrix',2,4)
CALL PRMT(B,LDB,M,N,'B matrix',2,4)
CALL PRMT(U,LDU,N,N,'U matrix',2,4)
C
C Checking the Frobenius norm of (UxA0-AxU),(UxB0-B) and (UxU'-I)
C without altering A,B,U,A0,B0.
C
SCALE = 1.D0
SUMSQ = 0.D0
DO 400 I = 1,N
CALL DGEMV('N',N,N,1.D0,A,LDA,U(1,I),1,0.D0,WORK,1)
CALL DGEMV('N',N,N,1.D0,U,LDU,A0(1,I),1,-1.D0,WORK,1)
CALL F06FJF(N,WORK,1,SCALE,SUMSQ)
400 CONTINUE
SUMSQ = SCALE*DSQRT(SUMSQ)
WRITE (2,FMT=980) SUMSQ
SCALE = 1.D0
SUMSQ = 0.D0
DO 500 I = 1,M
CALL DCOPY(N,B0(I,1),LDB,WORK,1)
CALL DGEMV('T',N,N,1.D0,U,LDU,B(I,1),LDB,-1.D0,WORK,1)
CALL F06FJF(N,WORK,1,SCALE,SUMSQ)
500 CONTINUE
SUMSQ = SCALE*DSQRT(SUMSQ)
WRITE (2,FMT=981) SUMSQ
SCALE = 1.D0
SUMSQ = 0.D0
DO 600 I = 1,N
CALL F06FBF(N,0.D0,WORK,1)
WORK(I) = 1.D0
CALL DGEMV('T',N,N,1.D0,U,LDU,U(1,I),1,-1.D0,WORK,1)
CALL F06FJF(N,WORK,1,SCALE,SUMSQ)
600 CONTINUE
SUMSQ = SCALE*DSQRT(SUMSQ)
WRITE (2,FMT=982) SUMSQ
IF (M.EQ.2) THEN
WRITE (2,FMT=945)
ELSE
WRITE (2,FMT=946)
END IF
700 CONTINUE
940 FORMAT (/ ' *** First example : upper Hessenberg form' /)
941 FORMAT (/ '1*** Second example : lower Hessenberg form' /)
945 FORMAT (
* '1*** This first example is a well-conditioned one.'/
* ' *** The above norm tests should be close to the machine '/
* ' *** precision and A, B, U should be close to those obtained'/
* ' *** on any other machine.')
946 FORMAT (
* '1*** This second example is an ill-conditioned one.'/
* ' *** Therefore A, B and U can differ a lot from those obtained'/
* ' *** on another machine, but the above norm tests should yet'/
* ' *** be close to the machine precision (because of backward'/
* ' *** stability).')
950 FORMAT (// ' *** Input Data *************' //)
951 FORMAT (// ' *** Output Data ************' //)
980 FORMAT (
* ' *** Testing norm U*A0-A*U =',D12.6,/
* ' *** which should be of the order of the machine precision'/
* ' *** norm(A)')
981 FORMAT (
* ' *** Testing norm U*B0-B =',D12.6,/
* ' *** which should be of the order of the machine precision'/
* ' *** norm(B)')
982 FORMAT (
* ' *** Testing norm U*UP-I =',D12.6,/
* ' *** which should be of the order of the machine precision')
C
C *** Last line of the program OBHESS *********************************
C
END
C
C This is the driver for SUBROUTINE COHESS.
C The routine is in TOMS.FOR and uses the file COHESS.IN as
C input file from which N, UPPER, TOL, A and B are read.
C Output is sent to file COHESS.OUT .
C
C .. Local Scalars ..
DOUBLE PRECISION SCALE,SUMSQ,TOL
INTEGER I,J,LDA,LDB,LDU,M,N
LOGICAL UPPER,WITHU
C ..
C .. Local Arrays ..
DOUBLE PRECISION A(10,10),A0(10,10),B(10,5),B0(10,5),U(10,10),
* WORK(10)
C ..
C .. External Subroutines ..
EXTERNAL COHESS,DCOPY,DGEMV,F06FBF,F06FJF
C ..
C .. Intrinsic Functions ..
INTRINSIC DSQRT
C ..
WITHU = .TRUE.
LDA = 10
LDB = 10
LDU = 10
C
C READ N, UPPER, TOL, A and B from file COHESS.IN
C The matrices A and B are to be read column by column.
C The input dimension M is specified by the loop index.
C
REWIND 1
READ (1,FMT='()')
DO 700 M = 2,3
READ (1,FMT=15) N,UPPER,TOL
15 FORMAT (I5,L5,D11.1)
17 FORMAT (1H ,'*** N =',I3,' M =',I3,' UPPER = ',L3,' TOL =',
* D8.1)
IF (M.EQ.2) THEN
WRITE (2,FMT=940)
ELSE
WRITE (2,FMT=941)
END IF
C
C The matrices A and B are read, and also stored in A0 and B0 for
C later use.
C
READ (1,FMT=52) ((A(I,J),I=1, N),J=1, N)
DO 51 J = 1,N
CALL DCOPY(N,A(1,J),1,A0(1,J),1)
51 CONTINUE
52 FORMAT (D25.15)
READ (1,FMT=52) ((B(I,J),I=1, N),J=1, M)
DO 61 J = 1,M
CALL DCOPY(N,B(1,J),1,B0(1,J),1)
61 CONTINUE
C
C The matrix U is initialized as the identity matrix.
C
DO 100 J = 1,N
DO 90 I = 1,N
U(I,J) = 0.D0
90 CONTINUE
U(J,J) = 1.D0
100 CONTINUE
WRITE (2,FMT=950)
WRITE (2,FMT=17) N,M,UPPER,TOL
CALL PRMT(A0,LDA,N,N,'A0 matr. ',2,4)
CALL PRMT(B0,LDB,N,M,'B0 matr. ',2,4)
C
C Calling the controller Hessenberg form routine.
C
CALL COHESS(A,LDA,N,B,LDB,M,U,LDU,WITHU,UPPER)
C
C The transformed matrices A and B, and the transformation matrix U
C are output.
C
WRITE (2,FMT=951)
CALL PRMT(A,LDA,N,N,'A matrix',2,4)
CALL PRMT(B,LDB,N,M,'B matrix',2,4)
CALL PRMT(U,LDU,N,N,'U matrix',2,4)
C
C Checking the Frobenius norm of (UxA0-AxU),(UxB0-B) and (UxU'-I)
C without altering A,B,U,A0,B0.
C
SCALE = 1.D0
SUMSQ = 0.D0
DO 400 I = 1,N
CALL DGEMV('N',N,N,1.D0,A,LDA,U(1,I),1,0.D0,WORK,1)
CALL DGEMV('N',N,N,1.D0,U,LDU,A0(1,I),1,-1.D0,WORK,1)
CALL F06FJF(N,WORK,1,SCALE,SUMSQ)
400 CONTINUE
SUMSQ = SCALE*DSQRT(SUMSQ)
WRITE (2,FMT=980) SUMSQ
SCALE = 1.D0
SUMSQ = 0.D0
DO 500 I = 1,M
CALL DCOPY(N,B(1,I),1,WORK,1)
CALL DGEMV('N',N,N,1.D0,U,LDU,B0(1,I),1,-1.D0,WORK,1)
CALL F06FJF(N,WORK,1,SCALE,SUMSQ)
500 CONTINUE
SUMSQ = SCALE*DSQRT(SUMSQ)
WRITE (2,FMT=981) SUMSQ
SCALE = 1.D0
SUMSQ = 0.D0
DO 600 I = 1,N
CALL F06FBF(N,0.D0,WORK,1)
WORK(I) = 1.D0
CALL DGEMV('T',N,N,1.D0,U,LDU,U(1,I),1,-1.D0,WORK,1)
CALL F06FJF(N,WORK,1,SCALE,SUMSQ)
600 CONTINUE
SUMSQ = SCALE*DSQRT(SUMSQ)
WRITE (2,FMT=982) SUMSQ
IF (M.EQ.2) THEN
WRITE (2,FMT=945)
ELSE
WRITE (2,FMT=946)
END IF
700 CONTINUE
940 FORMAT (' *** First example : upper Hessenberg form')
941 FORMAT ('1*** Second example : lower Hessenberg form')
945 FORMAT (
* '1*** This first example is a well-conditioned one.'/
* ' *** The above norm tests should be close to the machine'/
* ' *** precision and A, B, U should be close to those obtained'/
* ' *** on any other machine.')
946 FORMAT (
* '1*** This second example is an ill-conditioned one.'/
* ' *** Therefore A, B and U can differ a lot from those obtained'/
* ' *** on another machine, but the above norm tests should yet'/
* ' *** be close to the machine precision (because of backward'/
* ' *** stability).')
950 FORMAT (// ' *** Input Data *************' //)
951 FORMAT (// ' *** Output Data ************' //)
980 FORMAT (
* ' *** Testing norm U*A0-A*U =',D12.6,/
* ' *** which should be of the order of the machine precision'/
* ' *** norm(A)')
981 FORMAT (
* ' *** Testing norm U*B0-B =',D12.6,/
* ' *** which should be of the order of the machine precision'/
* ' *** norm(B)')
982 FORMAT (
* ' *** Testing norm U*UP-I =',D12.6,/
* ' *** which should be of the order of the machine precision')
C
C *** Last line of the program COHESS *********************************
END
C
C This is the driver for SUBROUTINE SRCFOB.
C The routine is in TOMS.FOR and uses the file SRCFOB.IN as
C input file from which N, P, A, B, C, R and Q are read.
C Output is sent to file SRCFOB.OUT .
C
INTEGER I, ISTEP, J, N, M, P, LDS, LDA, LDB, LDQ, LDC, LDR, LDK,
* LDW, LDU
DOUBLE PRECISION A(10,10), B(10,5), C(7,10), Q(5,5), R(7,7),
* WRK(22,22), S(10,10), UB(10,5),
* K(10,7), U(10,10), SSP(10,10),
* UPSSP(10,10), UPSSPU(10,10)
DOUBLE PRECISION DDOT, TOL
LOGICAL WITHU, UPPER, MULTBQ, WITHK
C
WITHK = .TRUE.
UPPER = .FALSE.
WITHU = .TRUE.
MULTBQ = .TRUE.
LDS = 10
LDA = 10
LDB = 10
LDC = 7
LDQ = 5
LDR = 7
LDK = 10
LDW = 22
LDU = 10
TOL = 1.D-15
C
C READ N, P, A, B, C, Q and R from the file SRCFOB.IN .
C The matrices A, B, C, Q and R are to be read columnwise.
C The input dimension M is specified by the loop index.
C
C
REWIND 1
DO 750 M = 2, 3
READ (1,51) N, P
51 FORMAT(2I5)
53 FORMAT(1H ,'*** N =', I3,' M =', I3,' P = ', I3)
IF (M .EQ. 2) THEN
WRITE(2,940)
ELSE
WRITE(2,941)
END IF
DO 50 J = 1, N
DO 50 I = 1, N
READ(1,52) A(I,J)
50 CONTINUE
52 FORMAT(D25.15)
DO 60 J = 1, M
DO 60 I = 1, N
READ(1,52) B(I,J)
60 CONTINUE
DO 68 J = 1, N
DO 68 I = 1, P
READ(1,52) C(I,J)
68 CONTINUE
DO 76 J = 1, P
DO 76 I = 1, P
READ(1,52) R(I,J)
76 CONTINUE
DO 84 J = 1, M
DO 84 I = 1, M
READ(1,52) Q(I,J)
84 CONTINUE
DO 90 J = 1, N
DO 90 I = 1, N
U(I,J) = 0.0D0
90 CONTINUE
DO 100 I = 1, N
U(I,I) = 1.0D0
100 CONTINUE
WRITE(2,950)
WRITE(2,947)
WRITE(2,53) N, M, P
WRITE(2,944)
CALL PRMT(A,LDA,N,N,'A matrix',2,4)
CALL PRMT(B,LDB,N,M,'B matrix',2,4)
CALL PRMT(C,LDC,P,N,'C matrix',2,4)
C
C Transform (A,B,C) to lower observer Hessenberg form.
C
CALL OBHESS(A, LDA, N, C, LDC, P, U, LDU, WITHU, UPPER)
DO 140 J = 1, M
DO 140 I = 1, N
UB(I,J) = DDOT(N, U(I,1), LDU, B(1,J), 1)
140 CONTINUE
WRITE(2,948)
CALL PRMT(A,LDA,N,N,'Au matr.',2,4)
CALL PRMT(B,LDB,N,M,'Bu matr.',2,4)
CALL PRMT(C,LDC,P,N,'Cu matr.',2,4)
CALL PRMT(U,LDU,N,N,'U matr. ',2,4)
WRITE(2,949)
CALL PRMT(R,LDR,P,P,'R matr. ',2,4)
CALL PRMT(Q,LDQ,M,M,'Q matr. ',2,4)
C
C Now perform three steps of the Kalman filter recursion
C (in square root covariance form) with MULTBQ = .TRUE.
C
WRITE(2,951)
C
C Initialize the S matrix to be the null matrix.
C
DO 350 J = 1, N
DO 350 I = 1, N
S(I,J) = 0.0D0
350 CONTINUE
DO 500 ISTEP = 1, 3
WRITE(2,935)ISTEP
CALL SRCFOB(S, LDS, A, LDA, UB, LDU, Q, LDQ, C, LDC, R,
* LDR, N, M, P, K, LDK, WRK, LDW, MULTBQ,
* WITHK, TOL)
CALL PRMT(S,LDS,N,N,'Su matr.',2,4)
CALL PRMT(K,LDK,N,P,'Ku matr.',2,4)
DO 450 J = 1, N
DO 450 I = 1, N
SSP(I,J) = DDOT(N, S(I,1), LDS, S(J,1), LDS)
450 CONTINUE
DO 460 J = 1, N
DO 460 I = 1, N
UPSSP(I,J) = DDOT(N, U(1,I), 1, SSP(1,J), 1)
460 CONTINUE
DO 470 J = 1, N
DO 470 I = 1, N
UPSSPU(I,J) = DDOT(N, UPSSP(I,1), LDU, U(1,J), 1)
470 CONTINUE
CALL PRMT(UPSSPU,LDU,N,N,'U''SuSu''U',2,4)
500 CONTINUE
WRITE(2,952)
C
C Initialize the S matrix to be the null matrix.
C
DO 550 J = 1, N
DO 550 I = 1, N
S(I,J) = 0.0D0
550 CONTINUE
C
C Now perform three steps of the Kalman filter recursion
C (in square root covariance form) with MULTBQ = .FALSE.
C
MULTBQ = .FALSE.
DO 700 ISTEP = 1, 3
WRITE(2,935)ISTEP
CALL SRCFOB(S, LDS, A, LDA, UB, LDU, Q, LDQ, C, LDC, R,
* LDR, N, M, P, K, LDK, WRK, LDW, MULTBQ,
* WITHK, TOL)
CALL PRMT(S,LDS,N,N,'Su matr.',2,4)
CALL PRMT(K,LDK,N,P,'Ku matr.',2,4)
DO 650 J = 1, N
DO 650 I = 1, N
SSP(I,J) = DDOT(N, S(I,1), LDS, S(J,1), LDS)
650 CONTINUE
DO 660 J = 1, N
DO 660 I = 1, N
UPSSP(I,J) = DDOT(N, U(1,I), 1, SSP(1,J), 1)
660 CONTINUE
DO 670 J = 1, N
DO 670 I = 1, N
UPSSPU(I,J) = DDOT(N, UPSSP(I,1), LDU, U(1,J), 1)
670 CONTINUE
CALL PRMT(UPSSPU,LDU,N,N,'U''SuSu''U',2,4)
700 CONTINUE
IF (M .EQ. 2) THEN
WRITE(2,945)
ELSE
WRITE(2,946)
END IF
750 CONTINUE
935 FORMAT(' *** ISTEP =', I3)
940 FORMAT(
* '1*** First example : Square root covariance filter with '/
* ' *** A, B, C in (lower) observer Hessenberg form and'/
* ' *** lower triangular Q, R.')
941 FORMAT(
* '1*** Second example : Square root covariance filter with'/
* ' *** A, B, C in (lower) observer Hessenberg form and'/
* ' *** lower triangular Q, R.')
944 FORMAT(// ' *** UPPER = .FALSE.' //)
945 FORMAT(
* '1*** In both these tests we start with Su=0 and perform three'/
* ' *** iterations of the filter.'/
* ' *** The ranks of Su in these three steps must be equal to '/
* ' *** M(=2), 2M(=4) and 3M(=6).'/
* ' *** K must be 0 in the first step and nonzero afterwards.'/
* ' *** The results for MULTBQ = .TRUE. and .FALSE. must be equal'/
* ' *** since we chose Q=I.'/
* ' *** The U''SuSu''U matrices are meant for comparison with '/
* ' *** SRCF.')
946 FORMAT(
* '1*** In both these tests we start with Su=0 and perform three'/
* ' *** iterations of the filter.'/
* ' *** The ranks of Su in these three steps must be equal to '/
* ' *** M(=3), 2M(=6) and min(N,3M)(=6).'/
* ' *** K must be 0 in the first step and nonzero afterwards.'/
* ' *** The results for MULTBQ = .TRUE. and .FALSE. must be equal'/
* ' *** since we chose Q=I.'/
* ' *** The U''SuSu''U matrices are meant for comparison with '/
* ' *** SRCF.')
947 FORMAT(// ' *** Input OBHESS' //)
948 FORMAT(// ' *** Output OBHESS' //)
949 FORMAT(// ' *** Additional input to SRCFOB' //)
950 FORMAT(// ' *** Input SRCFOB' //)
951 FORMAT(// ' *** Output SRCFOB for MULTBQ=.TRUE.' //)
952 FORMAT(// ' *** Output SRCFOB for MULTBQ=.FALSE.' //)
C
C *** Last line of the program SRCFOB *********************************
C
END
C
C This is the driver for SUBROUTINE SRIFCO.
C The routine is in TOMS.FOR and uses the file SRIFCO.IN as
C input file from which N, M, Ainv, C, AinvB, Qinv, Rinv, Z, X,
C and Y are read. Output is sent to file SRIFCO.OUT .
C
INTEGER I, ISTEP, J, N, M, P, LDS, LDA, LDB, LDC, LDR, LDQ, LDW,
* LDU, NMP
DOUBLE PRECISION AINV(10,10), AINVB(10,7), C(5,10), RINV(5,5),
* AINVU(10,10), AINVBU(10,7), CU(5,10),
* WRK(22,22), SINV(10,10), QINV(7,7), Y(5),
* SPS(10,10), Z(7), X(10), XU(10),
* RINVY(5), U(10,10),
* SINVU(10,10)
DOUBLE PRECISION DDOT, TOL
LOGICAL MULTRC, WITHU, UPPER, WITHX
C
WITHX = .TRUE.
UPPER = .TRUE.
MULTRC = .FALSE.
WITHU = .TRUE.
LDS = 10
LDA = 10
LDB = 10
LDQ = 7
LDC = 5
LDR = 5
LDW = 22
LDU = 10
TOL = 1.D-15
C
C READ N, M, Ainv, C, AinvB, Qinv, Rinv, Z, X, and Y from the file
C SRIFCO.IN.
C The matrices Ainv, C, AinvB, Qinv and Rinv are to be read column-
C wise.
C The input dimension P is specified by the loop index.
C
C
REWIND 1
DO 750 P = 2, 3
READ (1,51) N, M
NMP = N + M + P
IF (LDW .LT. NMP) WRITE(6,901)
51 FORMAT(2I5)
53 FORMAT(1H , '*** N =', I3, ' M =', I3, ' P = ', I3)
IF (P .EQ. 2) THEN
WRITE(2,940)
ELSE
WRITE(2,941)
END IF
DO 50 J = 1, N
DO 50 I =1, N
READ(1,52) AINV(J,I)
50 CONTINUE
52 FORMAT(D25.15)
DO 60 J = 1, P
DO 60 I = 1, N
READ(1,52) C(J,I)
60 CONTINUE
DO 68 I = 1, M
DO 68 J = 1, N
READ(1,52) AINVB(J,I)
68 CONTINUE
DO 76 J = 1, M
DO 76 I = 1, M
READ(1,52) QINV(J,I)
76 CONTINUE
DO 81 J = 1, P
DO 81 I = 1, P
READ(1,52) RINV(J,I)
81 CONTINUE
DO 86 J = 1, M
READ(1,52) Z(J)
86 CONTINUE
DO 88 J = 1, N
READ(1,52) X(J)
88 CONTINUE
DO 90 J = 1, P
READ(1,52) Y(J)
90 CONTINUE
C
C Initialize the U matrix to be the unity matrix.
C
DO 100 J = 1, N
DO 100 I = 1, N
U(I,J) = 0.0D0
100 CONTINUE
DO 110 I = 1, N
U(I,I) = 1.0D0
110 CONTINUE
C
WRITE(2,950)
WRITE(2,947)
WRITE(2,53) N, M, P
WRITE(2,944)
CALL PRMT(AINV,LDA,N,N,'Ainv ',2,4)
CALL PRMT(AINVB,LDA,N,M,'AinvB ',2,4)
CALL PRMT(C,LDC,P,N,'C matrix',2,4)
C
C Transform (A,B,C) to upper Hessenberg form.
C
CALL COHESS(AINV, LDA, N, AINVB, LDB, M, U, LDU, WITHU, UPPER)
DO 150 I = 1, P
CALL DGEMV('N', N, N, 1.0D0, U, LDU, C(I,1), LDC, 0.0D0,
* CU(I,1), LDC)
150 CONTINUE
WRITE(2,948)
CALL PRMT(AINV,LDA,N,N,'Ainvu ',2,4)
CALL PRMT(AINVB,LDA,N,M,'AinvBu ',2,4)
CALL PRMT(CU,LDC,P,N,'Cu matr.',2,4)
C
C Initialize the SINVu matrix to be the unity matrix.
C
DO 200 J = 1, N
DO 190 I = 1, N
SINVU(I,J) = 0.0D0
190 CONTINUE
SINVU(J,J) = 1.0D0
200 CONTINUE
C
CALL PRMT(SINVU,LDS,N,N,'Sinvu ',2,4)
WRITE(2,949)
CALL PRMT(QINV,LDQ,M,M,'QINV ',2,4)
CALL PRMT(RINV,LDR,P,P,'RINV ',2,4)
CALL PRMT(Z,LDQ,M,1,'Z vector',2,4)
CALL DGEMV('N', N, N, 1.0D0, U, LDU, X, 1, 0.0D0, XU, 1)
CALL PRMT(XU,LDA,N,1,'XU vect.',2,4)
CALL PRMT(Y,LDC,P,1,'Y vector',2,4)
C
C Calculation of RINV x Y.
C
DO 270 I = 1, P
RINVY(I) = DDOT(P, RINV(I,1), LDR, Y, 1)
270 CONTINUE
C
C Now perform four steps of the Kalman filter recursion
C (in square root covariance form).
C
WRITE(2,951)
DO 500 ISTEP = 1, 4
WRITE(2,935)ISTEP
CALL SRIFCO(SINVU, LDS, AINV, LDA, AINVB, LDB, RINV, LDR,
* CU, LDC, QINV, LDQ, XU, RINVY, Z, N, M, P,
* WRK, LDW, MULTRC, WITHX, TOL)
CALL PRMT(SINVU,LDS,N,N,'Sinvu ',2,4)
DO 440 I = 1, N
CALL DGEMV('N', N, N, 1.0D0, SINVU, LDS, U(1,I), 1,
* 0.0D0, SINV(1,I), 1)
440 CONTINUE
DO 460 J = 1, N
DO 450 I = 1, N
SPS(I,J) = DDOT(N, SINV(1,I), 1, SINV(1,J), 1)
450 CONTINUE
460 CONTINUE
CALL DGEMV('T', N, N, 1.0D0, U, LDU, XU, 1, 0.0D0, X, 1)
CALL PRMT(X,LDA,N,1,'X vector',2,4)
CALL PRMT(SPS,LDS,N,N,'Sin''Sin',2,4)
500 CONTINUE
IF (P .EQ. 2) THEN
WRITE(2,945)
ELSE
WRITE(2,946)
END IF
750 CONTINUE
900 FORMAT(' ', 8(D12.6,1X), D12.6)
901 FORMAT(' *********** Dimensions of WRK are less than N+M+P ')
935 FORMAT(' *** ISTEP =', I3)
940 FORMAT(