-
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.
- Loading branch information
Showing
7 changed files
with
71 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
include_directories(${PROJECT_SOURCE_DIR}/include/linalg) | ||
file(GLOB SOURCES "linalg/*.cpp") | ||
# file(GLOB SOURCES "linalg/*.cpp") | ||
set(SOURCES linalg/Matrix.cpp linalg/Solution.cpp linalg/Vectors.cpp) | ||
add_library(linalg-lib SHARED ${SOURCES}) | ||
|
||
add_executable (demo linalg/Main.cpp) | ||
add_executable (demo linalg/Demo.cpp) | ||
add_executable (theorems linalg/Theorems.cpp) | ||
|
||
target_link_libraries (demo linalg-lib) | ||
target_link_libraries(theorems linalg-lib) |
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,37 @@ | ||
#include <iostream> | ||
|
||
#include "Matrix.h" | ||
|
||
// make your own aliases | ||
typedef linalg::Matrix<double> Md; | ||
|
||
int main() { | ||
|
||
using std::cout; | ||
|
||
// A is the coefficient matrix | ||
Md A {{0,2,2,1,-2},{0,0,1,1,1},{0,0,0,0,2}}; | ||
|
||
// b is the column matrix of constants | ||
Md b {{2},{3},{4}}; | ||
|
||
linalg::Solution::SystemSolution solution = linalg::solve_linear_system(A, b); | ||
|
||
// prints "x1:a1, x2:2+0.5a2, x3:1-a2, x4:a2, x5:2 where a1, a2 are arbitrary parameters" | ||
cout << solution << "\n"; | ||
|
||
// prints 2, which is the number of free variables (a1, a2) | ||
cout << solution.num_free_variables << "\n"; | ||
|
||
// fun is a function that takes in a list of initialiser values (each corresponding to the free variables in their natural order (a1, a2, ..., an) and returns the values of all the variables for that particular combination of values | ||
auto fun = solution.get_compute_function(); | ||
|
||
// setting a1 = 1, a2 = 2 | ||
// prints: (1, 3, -1, 2, 2), which corresponds to x1: 1, x2: 3, x3: -1, x4: 2, x5: 2 | ||
cout << fun({1, 2}) << "\n"; | ||
|
||
// prints: (2, 3.5, -2, 3, 2) | ||
cout << fun({2, 3}) << "\n"; | ||
|
||
return 0; | ||
} |
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