addition: add row and column
This commit is contained in:
28
src/lib.rs
28
src/lib.rs
@@ -157,6 +157,34 @@ impl Matrix {
|
||||
None
|
||||
}
|
||||
|
||||
pub fn add_column(&mut self, data: Vec<Fraction>) -> Option<MatrixError> {
|
||||
if data.len() != self.columns {
|
||||
return Some(MatrixError::InvalidDataSize);
|
||||
}
|
||||
|
||||
for i in 0..data.len() {
|
||||
self.data.insert((i * self.rows) + self.rows - 1, data[i]);
|
||||
}
|
||||
|
||||
self.columns += 1;
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
pub fn add_row(&mut self, data: Vec<Fraction>) -> Option<MatrixError> {
|
||||
if data.len() != self.rows {
|
||||
return Some(MatrixError::InvalidDataSize);
|
||||
}
|
||||
|
||||
for i in 0..data.len() {
|
||||
self.data.push(data[i]);
|
||||
}
|
||||
|
||||
self.rows += 1;
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
fn partial_pivoting(&mut self, col: usize, sign: &mut Fraction) -> Result<bool, MatrixError> {
|
||||
if col >= self.columns {
|
||||
return Err(MatrixError::ColumnOutOfRange);
|
||||
|
||||
Reference in New Issue
Block a user