1: #region Translated by Jose Antonio De Santiago-Castillo.
2:
3: //Translated by Jose Antonio De Santiago-Castillo.
4: //E-mail:JAntonioDeSantiago@gmail.com
5: //Web: www.DotNumerics.com
6: //
7: //Fortran to C# Translation.
8: //Translated by:
9: //F2CSharp Version 0.71 (November 10, 2009)
10: //Code Optimizations: None
11: //
12: #endregion
13:
14: using System;
15: using DotNumerics.FortranLibrary;
16:
17: namespace DotNumerics.CSLapack
18: {
19: /// <summary>
20: /// -- LAPACK auxiliary routine (version 3.1) --
21: /// Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
22: /// November 2006
23: /// Purpose
24: /// =======
25: ///
26: /// DLANST returns the value of the one norm, or the Frobenius norm, or
27: /// the infinity norm, or the element of largest absolute value of a
28: /// real symmetric tridiagonal matrix A.
29: ///
30: /// Description
31: /// ===========
32: ///
33: /// DLANST returns the value
34: ///
35: /// DLANST = ( max(abs(A(i,j))), NORM = 'M' or 'm'
36: /// (
37: /// ( norm1(A), NORM = '1', 'O' or 'o'
38: /// (
39: /// ( normI(A), NORM = 'I' or 'i'
40: /// (
41: /// ( normF(A), NORM = 'F', 'f', 'E' or 'e'
42: ///
43: /// where norm1 denotes the one norm of a matrix (maximum column sum),
44: /// normI denotes the infinity norm of a matrix (maximum row sum) and
45: /// normF denotes the Frobenius norm of a matrix (square root of sum of
46: /// squares). Note that max(abs(A(i,j))) is not a consistent matrix norm.
47: ///
48: ///</summary>
49: public class DLANST
50: {
51:
52:
53: #region Dependencies
54:
55: LSAME _lsame; DLASSQ _dlassq;
56:
57: #endregion
58:
59:
60: #region Fields
61:
62: const double ONE = 1.0E+0; const double ZERO = 0.0E+0; int I = 0; double ANORM = 0; double SCALE = 0; double SUM = 0;
63:
64: #endregion
65:
66: public DLANST(LSAME lsame, DLASSQ dlassq)
67: {
68:
69:
70: #region Set Dependencies
71:
72: this._lsame = lsame; this._dlassq = dlassq;
73:
74: #endregion
75:
76: }
77:
78: public DLANST()
79: {
80:
81:
82: #region Dependencies (Initialization)
83:
84: LSAME lsame = new LSAME();
85: DLASSQ dlassq = new DLASSQ();
86:
87: #endregion
88:
89:
90: #region Set Dependencies
91:
92: this._lsame = lsame; this._dlassq = dlassq;
93:
94: #endregion
95:
96: }
97: /// <summary>
98: /// Purpose
99: /// =======
100: ///
101: /// DLANST returns the value of the one norm, or the Frobenius norm, or
102: /// the infinity norm, or the element of largest absolute value of a
103: /// real symmetric tridiagonal matrix A.
104: ///
105: /// Description
106: /// ===========
107: ///
108: /// DLANST returns the value
109: ///
110: /// DLANST = ( max(abs(A(i,j))), NORM = 'M' or 'm'
111: /// (
112: /// ( norm1(A), NORM = '1', 'O' or 'o'
113: /// (
114: /// ( normI(A), NORM = 'I' or 'i'
115: /// (
116: /// ( normF(A), NORM = 'F', 'f', 'E' or 'e'
117: ///
118: /// where norm1 denotes the one norm of a matrix (maximum column sum),
119: /// normI denotes the infinity norm of a matrix (maximum row sum) and
120: /// normF denotes the Frobenius norm of a matrix (square root of sum of
121: /// squares). Note that max(abs(A(i,j))) is not a consistent matrix norm.
122: ///
123: ///</summary>
124: /// <param name="NORM">
125: /// (input) CHARACTER*1
126: /// Specifies the value to be returned in DLANST as described
127: /// above.
128: ///</param>
129: /// <param name="N">
130: /// (input) INTEGER
131: /// The order of the matrix A. N .GE. 0. When N = 0, DLANST is
132: /// set to zero.
133: ///</param>
134: /// <param name="D">
135: /// (input) DOUBLE PRECISION array, dimension (N)
136: /// The diagonal elements of A.
137: ///</param>
138: /// <param name="E">
139: /// (input) DOUBLE PRECISION array, dimension (N-1)
140: /// The (n-1) sub-diagonal or super-diagonal elements of A.
141: ///</param>
142: public double Run(string NORM, int N, double[] D, int offset_d, double[] E, int offset_e)
143: {
144: double dlanst = 0;
145:
146: #region Array Index Correction
147:
148: int o_d = -1 + offset_d; int o_e = -1 + offset_e;
149:
150: #endregion
151:
152:
153: #region Strings
154:
155: NORM = NORM.Substring(0, 1);
156:
157: #endregion
158:
159:
160: #region Prolog
161:
162: // *
163: // * -- LAPACK auxiliary routine (version 3.1) --
164: // * Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
165: // * November 2006
166: // *
167: // * .. Scalar Arguments ..
168: // * ..
169: // * .. Array Arguments ..
170: // * ..
171: // *
172: // * Purpose
173: // * =======
174: // *
175: // * DLANST returns the value of the one norm, or the Frobenius norm, or
176: // * the infinity norm, or the element of largest absolute value of a
177: // * real symmetric tridiagonal matrix A.
178: // *
179: // * Description
180: // * ===========
181: // *
182: // * DLANST returns the value
183: // *
184: // * DLANST = ( max(abs(A(i,j))), NORM = 'M' or 'm'
185: // * (
186: // * ( norm1(A), NORM = '1', 'O' or 'o'
187: // * (
188: // * ( normI(A), NORM = 'I' or 'i'
189: // * (
190: // * ( normF(A), NORM = 'F', 'f', 'E' or 'e'
191: // *
192: // * where norm1 denotes the one norm of a matrix (maximum column sum),
193: // * normI denotes the infinity norm of a matrix (maximum row sum) and
194: // * normF denotes the Frobenius norm of a matrix (square root of sum of
195: // * squares). Note that max(abs(A(i,j))) is not a consistent matrix norm.
196: // *
197: // * Arguments
198: // * =========
199: // *
200: // * NORM (input) CHARACTER*1
201: // * Specifies the value to be returned in DLANST as described
202: // * above.
203: // *
204: // * N (input) INTEGER
205: // * The order of the matrix A. N >= 0. When N = 0, DLANST is
206: // * set to zero.
207: // *
208: // * D (input) DOUBLE PRECISION array, dimension (N)
209: // * The diagonal elements of A.
210: // *
211: // * E (input) DOUBLE PRECISION array, dimension (N-1)
212: // * The (n-1) sub-diagonal or super-diagonal elements of A.
213: // *
214: // * =====================================================================
215: // *
216: // * .. Parameters ..
217: // * ..
218: // * .. Local Scalars ..
219: // * ..
220: // * .. External Functions ..
221: // * ..
222: // * .. External Subroutines ..
223: // * ..
224: // * .. Intrinsic Functions ..
225: // INTRINSIC ABS, MAX, SQRT;
226: // * ..
227: // * .. Executable Statements ..
228: // *
229:
230: #endregion
231:
232:
233: #region Body
234:
235: if (N <= 0)
236: {
237: ANORM = ZERO;
238: }
239: else
240: {
241: if (this._lsame.Run(NORM, "M"))
242: {
243: // *
244: // * Find max(abs(A(i,j))).
245: // *
246: ANORM = Math.Abs(D[N + o_d]);
247: for (I = 1; I <= N - 1; I++)
248: {
249: ANORM = Math.Max(ANORM, Math.Abs(D[I + o_d]));
250: ANORM = Math.Max(ANORM, Math.Abs(E[I + o_e]));
251: }
252: }
253: else
254: {
255: if (this._lsame.Run(NORM, "O") || NORM == "1" || this._lsame.Run(NORM, "I"))
256: {
257: // *
258: // * Find norm1(A).
259: // *
260: if (N == 1)
261: {
262: ANORM = Math.Abs(D[1 + o_d]);
263: }
264: else
265: {
266: ANORM = Math.Max(Math.Abs(D[1 + o_d]) + Math.Abs(E[1 + o_e]), Math.Abs(E[N - 1 + o_e]) + Math.Abs(D[N + o_d]));
267: for (I = 2; I <= N - 1; I++)
268: {
269: ANORM = Math.Max(ANORM, Math.Abs(D[I + o_d]) + Math.Abs(E[I + o_e]) + Math.Abs(E[I - 1 + o_e]));
270: }
271: }
272: }
273: else
274: {
275: if ((this._lsame.Run(NORM, "F")) || (this._lsame.Run(NORM, "E")))
276: {
277: // *
278: // * Find normF(A).
279: // *
280: SCALE = ZERO;
281: SUM = ONE;
282: if (N > 1)
283: {
284: this._dlassq.Run(N - 1, E, offset_e, 1, ref SCALE, ref SUM);
285: SUM = 2 * SUM;
286: }
287: this._dlassq.Run(N, D, offset_d, 1, ref SCALE, ref SUM);
288: ANORM = SCALE * Math.Sqrt(SUM);
289: }
290: }
291: }
292: }
293: // *
294: dlanst = ANORM;
295: return dlanst;
296: // *
297: // * End of DLANST
298: // *
299:
300: #endregion
301:
302: }
303: }
304: }