Skip to content

Commit 7fcba4d

Browse files
committed
Create my-tri-diagona-matrix.cpp
1 parent 34feb4c commit 7fcba4d

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//三对角矩阵的方法
2+
//采用逐条对角线映射
3+
4+
template <typename anytype>
5+
anytype TriDiagonaMatrix<anytype>::get(int i, int j) const
6+
{
7+
if( i < 1 || i > n || j < 1 || j > n)
8+
{
9+
ostream os;
10+
os << "The index is not in bounds";
11+
return os.c_str();
12+
}
13+
14+
//确定要返回的元素
15+
switch(i - j)
16+
{
17+
case 1: return m_element[i - 2]; break; //下对角线
18+
case 0: return m_element[n + i - 2]; break; //主对角线
19+
case -1: return m_element[2 * n + i - 2]; break; //上对角线
20+
default: return 0;
21+
}
22+
}

0 commit comments

Comments
 (0)