Added row operators to matrixes. Row-echelon coming soon.
This commit is contained in:
parent
be59b70e00
commit
63e70f7124
20
Changelog.md
20
Changelog.md
@ -2,18 +2,38 @@
|
||||
|
||||
TODO
|
||||
|
||||
added row operations, fixed cofactor bugs, added setters
|
||||
|
||||
Here's the full changelog:
|
||||
```
|
||||
* Nerd_STF
|
||||
* Mathematics
|
||||
* Abstract
|
||||
* IMatrix
|
||||
+ AddRow(int, int, float)
|
||||
+ Cofactor()
|
||||
+ ScaleRow(int, float)
|
||||
+ SwapRows(int, int)
|
||||
+ SolveRowEchelon()
|
||||
* Algebra
|
||||
* Matrix
|
||||
+ AddRow(int, int, float)
|
||||
+ ScaleRow(int, float)
|
||||
+ SwapRows(int, int)
|
||||
= Fixed a blunder in `SignGrid(Int2)` with signs being incorrectly placed on matrixes with even column count.
|
||||
* Matrix2x2
|
||||
+ AddRow(int, int, float)
|
||||
+ ScaleRow(int, float)
|
||||
+ SwapRows(int, int)
|
||||
= Fixed a blunder in `Cofactor()` with the position of elements.
|
||||
* Matrix3x3
|
||||
+ AddRow(int, int, float)
|
||||
+ ScaleRow(int, float)
|
||||
+ SwapRows(int, int)
|
||||
* Matrix4x4
|
||||
+ AddRow(int, int, float)
|
||||
+ ScaleRow(int, float)
|
||||
+ SwapRows(int, int)
|
||||
* NumberSystems
|
||||
* Complex
|
||||
+ operator Complex(SystemComplex)
|
||||
|
||||
@ -10,6 +10,12 @@ public interface IMatrix<T> : IAbsolute<T>, ICeiling<T>, IClamp<T>, IDivide<T>,
|
||||
public float Determinant();
|
||||
public T? Inverse();
|
||||
public T Transpose();
|
||||
|
||||
public T AddRow(int rowToChange, int referenceRow, float factor = 1);
|
||||
public T ScaleRow(int rowIndex, float value);
|
||||
public T SwapRows(int rowA, int rowB);
|
||||
|
||||
//public T SolveRowEchelon();
|
||||
}
|
||||
|
||||
public interface IMatrix<This, TMinor> : IMatrix<This> where This : IMatrix<This, TMinor>
|
||||
|
||||
@ -3,5 +3,5 @@
|
||||
public interface IStaticMatrix<T> : IAverage<T>, IMatrix<T>, IMedian<T>,
|
||||
IMatrixPresets<T> where T : IStaticMatrix<T>
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -276,6 +276,35 @@ public class Matrix : IMatrix<Matrix, Matrix>
|
||||
});
|
||||
}
|
||||
|
||||
public Matrix AddRow(int rowToChange, int referenceRow, float factor = 1)
|
||||
{
|
||||
Matrix @this = this;
|
||||
return new(Size, delegate (int r, int c)
|
||||
{
|
||||
if (r == rowToChange) return @this[r, c] += factor * @this[referenceRow, c];
|
||||
else return @this[r, c];
|
||||
});
|
||||
}
|
||||
public Matrix ScaleRow(int rowIndex, float factor)
|
||||
{
|
||||
Matrix @this = this;
|
||||
return new(Size, delegate (int r, int c)
|
||||
{
|
||||
if (r == rowIndex) return @this[r, c] * factor;
|
||||
else return @this[r, c];
|
||||
});
|
||||
}
|
||||
public Matrix SwapRows(int rowA, int rowB)
|
||||
{
|
||||
Matrix @this = this;
|
||||
return new(Size, delegate (int r, int c)
|
||||
{
|
||||
if (r == rowA) return @this[rowB, c];
|
||||
else if (r == rowB) return @this[rowA, c];
|
||||
else return @this[r, c];
|
||||
});
|
||||
}
|
||||
|
||||
public override bool Equals([NotNullWhen(true)] object? obj)
|
||||
{
|
||||
if (obj == null) return base.Equals(obj);
|
||||
|
||||
@ -241,6 +241,36 @@ public record class Matrix2x2 : IStaticMatrix<Matrix2x2>
|
||||
{ r1c2, r2c2 }
|
||||
});
|
||||
|
||||
public Matrix2x2 AddRow(int rowToChange, int referenceRow, float factor = 1)
|
||||
{
|
||||
Matrix2x2 @this = this;
|
||||
return new(delegate (int r, int c)
|
||||
{
|
||||
if (r == rowToChange) return @this[r, c] += factor * @this[referenceRow, c];
|
||||
else return @this[r, c];
|
||||
});
|
||||
}
|
||||
public Matrix2x2 ScaleRow(int rowIndex, float factor)
|
||||
{
|
||||
Matrix2x2 @this = this;
|
||||
return new(delegate (int r, int c)
|
||||
{
|
||||
if (r == rowIndex) return @this[r, c] * factor;
|
||||
else return @this[r, c];
|
||||
});
|
||||
}
|
||||
public Matrix2x2 SwapRows(int rowA, int rowB)
|
||||
{
|
||||
Matrix2x2 @this = this;
|
||||
return new(delegate (int r, int c)
|
||||
{
|
||||
if (r == rowA) return @this[rowB, c];
|
||||
else if (r == rowB) return @this[rowA, c];
|
||||
else return @this[r, c];
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public virtual bool Equals(Matrix2x2? other)
|
||||
{
|
||||
if (other is null) return false;
|
||||
|
||||
@ -336,6 +336,35 @@ public record class Matrix3x3 : IStaticMatrix<Matrix3x3>
|
||||
{ r1c3, r2c3, r3c3 }
|
||||
});
|
||||
|
||||
public Matrix3x3 AddRow(int rowToChange, int referenceRow, float factor = 1)
|
||||
{
|
||||
Matrix3x3 @this = this;
|
||||
return new(delegate (int r, int c)
|
||||
{
|
||||
if (r == rowToChange) return @this[r, c] += factor * @this[referenceRow, c];
|
||||
else return @this[r, c];
|
||||
});
|
||||
}
|
||||
public Matrix3x3 ScaleRow(int rowIndex, float factor)
|
||||
{
|
||||
Matrix3x3 @this = this;
|
||||
return new(delegate (int r, int c)
|
||||
{
|
||||
if (r == rowIndex) return @this[r, c] * factor;
|
||||
else return @this[r, c];
|
||||
});
|
||||
}
|
||||
public Matrix3x3 SwapRows(int rowA, int rowB)
|
||||
{
|
||||
Matrix3x3 @this = this;
|
||||
return new(delegate (int r, int c)
|
||||
{
|
||||
if (r == rowA) return @this[rowB, c];
|
||||
else if (r == rowB) return @this[rowA, c];
|
||||
else return @this[r, c];
|
||||
});
|
||||
}
|
||||
|
||||
public virtual bool Equals(Matrix3x3? other)
|
||||
{
|
||||
if (other is null) return false;
|
||||
|
||||
@ -451,6 +451,35 @@ public record class Matrix4x4 : IStaticMatrix<Matrix4x4>
|
||||
{ r1c4, r2c4, r3c4, r4c4 }
|
||||
});
|
||||
|
||||
public Matrix4x4 AddRow(int rowToChange, int referenceRow, float factor = 1)
|
||||
{
|
||||
Matrix4x4 @this = this;
|
||||
return new(delegate (int r, int c)
|
||||
{
|
||||
if (r == rowToChange) return @this[r, c] += factor * @this[referenceRow, c];
|
||||
else return @this[r, c];
|
||||
});
|
||||
}
|
||||
public Matrix4x4 ScaleRow(int rowIndex, float factor)
|
||||
{
|
||||
Matrix4x4 @this = this;
|
||||
return new(delegate (int r, int c)
|
||||
{
|
||||
if (r == rowIndex) return @this[r, c] * factor;
|
||||
else return @this[r, c];
|
||||
});
|
||||
}
|
||||
public Matrix4x4 SwapRows(int rowA, int rowB)
|
||||
{
|
||||
Matrix4x4 @this = this;
|
||||
return new(delegate (int r, int c)
|
||||
{
|
||||
if (r == rowA) return @this[rowB, c];
|
||||
else if (r == rowB) return @this[rowA, c];
|
||||
else return @this[r, c];
|
||||
});
|
||||
}
|
||||
|
||||
public virtual bool Equals(Matrix4x4? other)
|
||||
{
|
||||
if (other is null) return false;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user