File size: 8,720 Bytes
b1b3bae |
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 |
#region Copyright � 2009, De Santiago-Castillo JA. All rights reserved.
//Copyright � 2009 Jose Antonio De Santiago-Castillo
//E-mail:JAntonioDeSantiago@gmail.com
//Web: www.DotNumerics.com
//
#endregion
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
namespace DotNumerics.LinearAlgebra
{
/// <summary>
/// Represents the base class for band matrices.
/// </summary>
public abstract class BaseBandMatrix: BaseMatrix
{
#region Fields
/// <summary>
/// Number of bands below the main diagonal (lowerBandWidth)
/// </summary>
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
protected int MeLowerBandWidth;
/// <summary>
/// Number of bands above the main diagonal (upperBandWidth)
/// </summary>
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
protected int MeUpperBandWidth;
///// <summary>
///// Number of rows of the reduced matrix
///// </summary>
//[DebuggerBrowsable(DebuggerBrowsableState.Never)]
//private int MeReducedMatrixRows;
#endregion
#region Public Constructors
/// <summary>
/// Initializes a new instance of the BandMatrix class of the given size.
/// </summary>
/// <param name="rows">Number of rows.</param>
/// <param name="columns">Number of columns.</param>
/// <param name="lowerBandWidth">Number of bands below the main diagonal</param>
/// <param name="upperBandWidth">Number of bands above the main diagonal</param>
public BaseBandMatrix(int rows, int columns, int lowerBandWidth, int upperBandWidth)
: base(rows, columns)
{
if (lowerBandWidth < 0 || lowerBandWidth >= rows) throw new System.ArgumentException("lowerBandWidth < 0 || lowerBandWidth >= rows"); //Debe de ser menor que rows
if (upperBandWidth < 0 || upperBandWidth >= columns) throw new System.ArgumentException("upperBandWidth < 0 || upperBandWidth >= columns"); //Debe de ser menor que columns
// For an m by n matrix A with band widths ml and mu, the array AGB must have a leading dimension, lda,
//greater than or equal to ml+mu+1. The size of the second dimension must be (at least) n, the number of columns in the matrix.
//Using the array AGB, which is declared as AGB(ml+mu+1, n)
this.MeLowerBandWidth = lowerBandWidth;
this.MeUpperBandWidth = upperBandWidth;
//this.MeReducedMatrixRows = lowerBandWidth + upperBandWidth + 1;
}
/// <summary>
/// Initializes a new instance of the BandMatrix class of the given size using a array
/// </summary>
/// <param name="rows">Number of rows.</param>
/// <param name="columns">Number of columns.</param>
/// <param name="lowerBandWidth">Number of bands below the main diagonal</param>
/// <param name="upperBandWidth">Number of bands above the main diagonal</param>
/// <param name="Data">The matix data </param>
internal BaseBandMatrix(int rows, int columns, int lowerBandWidth, int upperBandWidth, double[] Data)
: base(rows, columns, Data)
{
if (lowerBandWidth < 0 || lowerBandWidth >= rows) throw new System.ArgumentException("lowerBandWidth < 0 || lowerBandWidth >= rows"); //Debe de ser menor que rows
if (upperBandWidth < 0 || upperBandWidth >= columns) throw new System.ArgumentException("upperBandWidth < 0 || upperBandWidth >= columns"); //Debe de ser menor que columns
this.MeLowerBandWidth = lowerBandWidth;
this.MeUpperBandWidth = upperBandWidth;
//this.MeReducedMatrixRows = lowerBandWidth + upperBandWidth + 1;
}
/// <summary>
/// Initializes a new instance of the BandMatrix class of the given size using a array
/// </summary>
/// <param name="size">Size</param>
/// <param name="lowerBandWidth">Number of bands below the main diagonal</param>
/// <param name="upperBandWidth">Number of bands above the main diagonal</param>
internal BaseBandMatrix(int size, int lowerBandWidth, int upperBandWidth)
: base(size)
{
if (lowerBandWidth < 0 || lowerBandWidth >= size) throw new System.ArgumentException("lowerBandWidth < 0 || lowerBandWidth >= rows"); //Debe de ser menor que rows
if (upperBandWidth < 0 || upperBandWidth >= size) throw new System.ArgumentException("upperBandWidth < 0 || upperBandWidth >= columns"); //Debe de ser menor que columns
this.MeLowerBandWidth = lowerBandWidth;
this.MeUpperBandWidth = upperBandWidth;
//this.MeReducedMatrixRows = lowerBandWidth + upperBandWidth + 1;
}
/// <summary>
/// Initializes a new instance of the BandMatrix class of the given size using a array
/// </summary>
/// <param name="size">Size</param>
/// <param name="Data">The matix data </param>
/// <param name="lowerBandWidth">Number of bands below the main diagonal</param>
/// <param name="upperBandWidth">Number of bands above the main diagonal</param>
internal BaseBandMatrix(int size, int lowerBandWidth, int upperBandWidth, double[] Data)
: base(size, Data)
{
if (lowerBandWidth < 0 || lowerBandWidth >= size) throw new System.ArgumentException("lowerBandWidth < 0 || lowerBandWidth >= rows"); //Debe de ser menor que rows
if (upperBandWidth < 0 || upperBandWidth >= size) throw new System.ArgumentException("upperBandWidth < 0 || upperBandWidth >= columns"); //Debe de ser menor que columns
this.MeLowerBandWidth = lowerBandWidth;
this.MeUpperBandWidth = upperBandWidth;
//this.MeReducedMatrixRows = lowerBandWidth + upperBandWidth + 1;
}
#endregion
#region Overloading Operators
#endregion
#region Public Methods
/// <summary>
/// Returns the value of a element of the matrix.
/// </summary>
/// <param name="row">The row value (zero-based).</param>
/// <param name="column">The column value (zero-based).</param>
/// <returns>The matrix value at (row, column).</returns>
public override double this[int row, int column]
{
get
{
if (column >= this._ColumnCount)
{
throw new ArgumentException("Index was outside the bounds of the matrix.");
}
return this._Data[row + column * this._RowCount];
}
set
{
if (column >= this._ColumnCount)
{
throw new ArgumentException("Index was outside the bounds of the matrix.");
}
//A general band matrix has its nonzero elements arranged uniformly near the diagonal, such that:
//aij = 0 if (i-j) > ml or (j-i) > mu
if ((row - column) <= this.MeLowerBandWidth && (column - row) <= this.MeUpperBandWidth)
{
this._Data[row + column * this._RowCount] = value;
}
}
}
/// <summary>
/// Number of bands below the main diagonal (lowerBandWidth)
/// </summary>
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
public int LowerBandWidth
{
get { return MeLowerBandWidth; }
}
/// <summary>
/// Number of bands above the main diagonal (upperBandWidth)
/// </summary>
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
public int UpperBandWidth
{
get { return MeUpperBandWidth; }
}
#region Static methods
/// <summary>
/// Implicit BaseBandMatrix to Matrix conversion.
/// </summary>
/// <param name="bandMatrix">The BandMatrix</param>
/// <returns>The Matrix.</returns>
public static implicit operator Matrix(BaseBandMatrix bandMatrix)
{
Matrix NewMatrix = new Matrix(bandMatrix.RowCount, bandMatrix.ColumnCount, bandMatrix.Data);
return NewMatrix;
}
#endregion
#endregion
#region Private Methods
#endregion
}
} |