This project is a C++ library that implements data types for vectors and matrices, offering a comprehensive set of mathematical operations commonly used in various applications.
- Click on the Option button in the UI.
- Select Load Data to load a text file containing vectors and/or matrices.
- Input the desired operation in the Command column.
- Press the Execute button to perform the operation.
The input text file can contain two data types: vectors and matrices. Each row in the text file represents a vector or a matrix in the following format:
To represent a vector, use the following format:
{dimension}
: The dimension of the vector (number of elements).{value1} {value2} ... {valueN}
: The values of the vector's elements.
// V {dimention} {value}
V 3 1 2 3
To represent a matrix, use the following format:
{rows}
: The number of rows in the matrix.{cols}
: The number of columns in the matrix.{value1} {value2} ... {valueN}
: The values of the matrix elements in row-major order.
// M {rows} {cols} {value}
M 3 2 0 1 2 3 4 5 // row=3, col=2
This section introduces vector operator functions that perform element-wise operations on vectors. If one of the input vectors is 1D, the operation will be a scalar operation.
Operator | Description | Input | Output |
---|---|---|---|
+ |
Element-wise addition of vectors. | ||
- |
Element-wise subtraction of vectors. | ||
* |
Element-wise product of vectors. |
The following functionalities have been implemented in the vector functions:
Function | Description | Input | Output |
---|---|---|---|
dot(a, b) |
Compute the dot product of two vectors. | ||
norm(a) |
Calculate the norm (magnitude) of a vector. | ||
normal(a) |
Normalize a vector to a unit vector. | ||
cross(a, b) |
Compute the cross product of two 3D vectors. | ||
com(a, b) |
Find the component of vector a along vector b. | ||
proj(a, b) |
Compute the projection of vector a onto vector b. | ||
area(a, b) |
Calculate the area of the triangle formed by vectors a and b. | ||
angle(a, b) |
Determine the angle (in radians) between two vectors. | ||
pn(a, b) |
Compute the normal vector of the plane formed by two 3D vectors. | ||
ob(a, b, c ...) |
Use Gram-Schmidt process to find orthonormal basis from multiple vectors. | String Vector array (not for operation)
|
Judgement Functions π§ This section includes functions to assess the relationship between two vectors.
Function | Description | Input | Output |
---|---|---|---|
isparallel(a, b) |
Checks if vectors a and b are parallel. | String: Yes or No
|
|
isorthogonal(a, b) |
Checks if vectors a and b are orthogonal. | String: Yes or No
|
|
isli(a, b) |
Checks if vectors a and b are linearly independent. | String: Yes or No
|
If one of the matrices has a size of 1x1, the library will perform a scalar product, which is a special operation that treats the matrix as a scalar value.
Operator | Description | Input | Output |
---|---|---|---|
+ |
Element-wise addition. |
|
|
- |
Element-wise subtraction. |
|
|
* |
Element-wise product. |
|
Function | Description | Input | Output |
---|---|---|---|
matmul(A, B) |
Performs matrix multiplication between two matrices A and B. |
|
|
rank(A) |
Calculates the rank of a matrix. | ||
trans(A) |
Computes the transpose of a matrix A. | ||
solve(A, B) |
Solves a linear system of equations of the form |
|
|
det(A) |
Calculates the determinant of a Matrix | ||
inverse(A) |
Finds the inverse matrix of a square matrix A. | ||
adj(A) |
Computes the adjoint of a matrix | ||
pm(A) |
Finds Largest Eigenvalue and Eigenvector by using the power method | String: Eigenvalue and Eigenvector
|
|
eigen(A) |
Find Eigenvalue and Eigenvector of matrix A. | String: Eigenvalue and Eigenvector
|
|
leastq |
Applies The Method of Least Squares. |
|
|
rref(A) |
Converts matrix A to its reduced row echelon form. |
To add a new function or change the usage of existing functions, follow these steps:
1. Implement a Subclass of ICommand
in Command.h
- Create a new subclass of
ICommand
in theCommand.h
file. Make sure to override theoperate
method to define the functionality of your command. For example:
class YourCommand : public ICommand {
public:
YourCommand() {
operand_count_ = 2;
return_type_ = ReturnType::Operand; // or ReturnType::String
}
Vector operate(std::vector<Vector>& operands) override;
};
2. Register Your Command
In the WindowsForm.h
file, locate the InitializeCommands()
function, and register your newly implemented command using the command_factory->RegisterCommand()
method. This step ensures that your command becomes available in the application. For example:
void InitializeCommands() {
command_factory = new CommandFactory();
// Existing vector commands
command_factory->RegisterCommand("dot", std::make_shared<DotCommand>());
// ...
// Register your custom command
command_factory->RegisterCommand("yourcommand", std::make_shared<YourCommand>());
}
By following these steps, you can easily add new mathematical functions or modify the behavior of existing functions within the application.