addition: add row and column

This commit is contained in:
2026-04-28 07:23:28 -06:00
parent 41ec49857f
commit 6757e85eaf

View File

@@ -157,6 +157,34 @@ impl Matrix {
None 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> { fn partial_pivoting(&mut self, col: usize, sign: &mut Fraction) -> Result<bool, MatrixError> {
if col >= self.columns { if col >= self.columns {
return Err(MatrixError::ColumnOutOfRange); return Err(MatrixError::ColumnOutOfRange);