-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from HamletTanyavong/dev
Add vectors, matrices, and QR decomposition
- Loading branch information
Showing
20 changed files
with
1,897 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// <copyright file="ExternalExtensions.cs" company="Mathematics.NET"> | ||
// Mathematics.NET | ||
// https://github.com/HamletTanyavong/Mathematics.NET | ||
// | ||
// MIT License | ||
// | ||
// Copyright (c) 2023 Hamlet Tanyavong | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in all | ||
// copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
// SOFTWARE. | ||
// </copyright> | ||
|
||
using System.Text; | ||
|
||
namespace Mathematics.NET; | ||
|
||
/// <summary>A class containing extension methods for external .NET objects</summary> | ||
public static class ExternalExtensions | ||
{ | ||
/// <summary>Remove specified characters from the end of a string being built by a string builder</summary> | ||
/// <param name="builder">A string builder instance</param> | ||
/// <param name="unwantedChars">An array of characters to trim</param> | ||
/// <returns>The same string builder with characters removed</returns> | ||
public static StringBuilder TrimEnd(this StringBuilder builder, params char[]? unwantedChars) | ||
{ | ||
if (unwantedChars == null || builder.Length == 0 || unwantedChars.Length == 0) | ||
{ | ||
return builder; | ||
} | ||
|
||
int i = builder.Length - 1; | ||
while (i >= 0) | ||
{ | ||
if (!unwantedChars.Contains(builder[i])) | ||
{ | ||
break; | ||
} | ||
i--; | ||
} | ||
if (i < builder.Length - 1) | ||
{ | ||
builder.Length = ++i; | ||
} | ||
|
||
return builder; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
src/Mathematics.NET/LinearAlgebra/Abstractions/ISquareMatrix.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// <copyright file="ISquareMatrix.cs" company="Mathematics.NET"> | ||
// Mathematics.NET | ||
// https://github.com/HamletTanyavong/Mathematics.NET | ||
// | ||
// MIT License | ||
// | ||
// Copyright (c) 2023 Hamlet Tanyavong | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in all | ||
// copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
// SOFTWARE. | ||
// </copyright> | ||
|
||
namespace Mathematics.NET.LinearAlgebra.Abstractions; | ||
|
||
/// <summary>Defines support for square matrices</summary> | ||
/// <typeparam name="T">A type that implements <see cref="ITwoDimensionalArrayRepresentable{T, U}"/></typeparam> | ||
/// <typeparam name="U">A type that implements <see cref="IComplex{T}"/></typeparam> | ||
public interface ISquareMatrix<T, U> | ||
where T : ITwoDimensionalArrayRepresentable<T, U> | ||
where U : IComplex<U> | ||
{ | ||
/// <summary>Represents a value that is not a matrix</summary> | ||
/// <remarks>This result will be returned when trying to invert a singular matrix</remarks> | ||
static abstract T NaM { get; } | ||
|
||
/// <summary>Compute the determinant of the matrix</summary> | ||
/// <returns>The determinant</returns> | ||
U Determinant(); | ||
|
||
/// <summary>Compute the inverse of the matrix</summary> | ||
/// <returns>The inverse if the matrix is invertible; otherwise, <see cref="NaM"/></returns> | ||
T Inverse(); | ||
|
||
/// <summary>Check if a value is not a matrix</summary> | ||
/// <param name="matrix">The value to check</param> | ||
/// <returns><see langword="true"/> if the value is not a matrix; otherwise, <see langword="false"/></returns> | ||
static abstract bool IsNaM(T matrix); | ||
|
||
/// <summary>Compute the trace of the matrix</summary> | ||
/// <returns>The trace</returns> | ||
U Trace(); | ||
} |
57 changes: 57 additions & 0 deletions
57
src/Mathematics.NET/LinearAlgebra/Abstractions/ITwoDimensionalArrayRepresentable.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// <copyright file="ITwoDimensionalArrayRepresentable.cs" company="Mathematics.NET"> | ||
// Mathematics.NET | ||
// https://github.com/HamletTanyavong/Mathematics.NET | ||
// | ||
// MIT License | ||
// | ||
// Copyright (c) 2023 Hamlet Tanyavong | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in all | ||
// copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
// SOFTWARE. | ||
// </copyright> | ||
|
||
using Mathematics.NET.Core.Operations; | ||
using Mathematics.NET.Core.Relations; | ||
|
||
namespace Mathematics.NET.LinearAlgebra.Abstractions; | ||
|
||
/// <summary>Defines support for mathematical objects that can be represented by two-dimensional arrays</summary> | ||
/// <typeparam name="T">The type that implements the interface</typeparam> | ||
/// <typeparam name="U">A type that implements <see cref="IComplex{T}"/></typeparam> | ||
public interface ITwoDimensionalArrayRepresentable<T, U> | ||
: IArrayRepresentable<U>, | ||
IAdditionOperation<T, T>, | ||
ISubtractionOperation<T, T>, | ||
IMultiplicationOperation<T, T>, | ||
IEqualityRelation<T, bool>, | ||
IFormattable | ||
where T : ITwoDimensionalArrayRepresentable<T, U> | ||
where U : IComplex<U> | ||
{ | ||
/// <summary>The number of rows in the array</summary> | ||
static abstract int E1Components { get; } | ||
|
||
/// <summary>The number of columns in the array</summary> | ||
static abstract int E2Components { get; } | ||
|
||
/// <summary>Get the element at the specified row and column</summary> | ||
/// <param name="row">The row</param> | ||
/// <param name="column">The column</param> | ||
/// <returns>The element at the specified row and column</returns> | ||
U this[int row, int column] { get; set; } | ||
} |
Oops, something went wrong.