Skip to content

Commit

Permalink
added gif
Browse files Browse the repository at this point in the history
  • Loading branch information
RS2007 committed Jun 15, 2022
1 parent a5e83cf commit ea3cd17
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 45 deletions.
114 changes: 71 additions & 43 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,76 +1,104 @@
## A Custom linear algebra library
***

### About
<p>This project is an attempt to implement whatever I learned during my introductory linear algebra course during my first year of engineering. </p>

<h3>Problem</h3>
---


<h4>Input for solving a linear system of equations </h4>
### Motivation
<p>The reason for building this project was to implement the common linear algebra algorithms that were introduced during the introductory linear algebra course during my freshman year</p>

<br>

### Demo
<br>

<img src="./images/Math_white.svg" id="math" style="filter:invert(1)">
$$2*x+5*y+z=20$$
$$4*x+5*y+z=10$$
$$6x+5y=0$$
$$A = \begin{pmatrix} 2 & 5 & 1\\ 4 & 5 & 1\\ 6 & 5 & 0\end{pmatrix}$$
$$B = \begin{pmatrix} 20 \\ 10 \\ 0\end{pmatrix}$$

> If you have difficulty viewing this image, checkout the image [here](/images/Math_black.svg)
Solution => $ x=-5,y=6,z=0$


<br/>
<br/>

<h4>Main function</h4>

![img.png](images/input.png)


<h4>Output</h4>

![Output.png](images/Output.png)


### What can it do?
***
- Matrix multiplication
- Currently,this is done using the naive O(n^3) algorithm (```mat_mul_naive``` function in the code)
- The plan is to shift this to strassen's algorithm(```mat_mul_strassen`` function in the code)
![./images/gif.gif](./images/gif.gif)

### What can it do?

---

**Data structures**:
- Matrix(```mat```)
- ```c
{
unsigned int num_rows;
unsigned int num_cols;
double **data;
int isSquare;
}
```
-LUP Matrix(```mat_lup```)
- ```c
{
mat *L;
mat *U;
mat *P;
unsigned int num_permutations;
}
```

**API**:

- Matrix addition
- ```mat* mat_add(mat* a,mat* b)```
- Matrix subtraction
- ```mat* mat_subtract(mat* a,mat* b)```
- Matrix multiplication
- ```mat* mat_mul_naive(mat* a,mat* b)```
- Finding Row Echelon Form of a Matrix
- ```mat* mat_ref(mat* a) ```
- Finding Reduced Row Echelon Form of a Matrix
- ```mat* mat_rref(mat* a)```
- LU decomposition
- ```mat_lup* mat_LU(mat* a) ```
- Solving linear equations
- Multiple Implementations of the same
- ```solve_linear_forward``` using the forward substitution method
- ```solve_linear_backward``` using the backward substitution method
- ```mat* solve_linear_LU(mat* a,mat* b)```
- Finding the inverse
- Using LU method
- ```mat* mat_inverse(mat* a)```
- Finding the determinant
- QR decomposition

- ```double mat_determinant(mat* a)```


### Background and References
***

- I was completely new to C when I started with this project
- I had done a freshmen introduction to linear algebra so I was kind of familiar with the mathematical concepts
---

- I was completely new to C when I started with this project.
- I had done a freshmen introduction to linear algebra so I was kind of familiar with the mathematical concepts.
- References:
- 3b1b Linear Algebra playlist
- Linear Algebra playlist from Khan Academy
- Linear Algebra playlist from MathTheBeautiful
- [3b1b Linear Algebra playlist](https://www.youtube.com/watch?v=kjBOesZCoqc&list=PL0-GT3co4r2y2YErbmuJw2L5tW4Ew2O5B)
- [Linear Algebra playlist from Khan Academy](https://www.khanacademy.org/math/linear-algebra)
- [Linear Algebra playlist from MathTheBeautiful](https://www.youtube.com/watch?v=odV3oJOpE8s&list=PLlXfTHzgMRUIqYrutsFXCOmiqKUgOgGJ5)
- The C programming language(Dennis Ritchie and Brian Kernighan)

### Can this be used in production?
***
<p>Definitely not, this project was build for educational purposes only and this is definitely not a library that one should use for their projects</p>

---

<p>Definitely not. This project was build for educational purposes only and this is definitely not a library that one should use for their projects.</p>

### Future of this project
***
- This project is far from complete
- Some new features to be implemented
- A CLI interface for users

---

- This project is far from complete.
- Some new features to be implemented:
- A CLI interface for users
- Replacing current makefile with CMake
- Computing eigenvalues and eignevectors
- Adding faster algorithms and better data structures
- Addition of strassen's algorithm for matrix multiplicaton
- Dense and sparse matrices
- More...


Binary file added images/gif.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ mat *solve_linear_LU(mat *A, mat *b);
mat *mat_inverse();

// determinant of matrix using LU(P)
mat *mat_determinant();
double *mat_determinant();

// QR decomposition
mat *mat_QR();
Expand Down
4 changes: 3 additions & 1 deletion test.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ int main(int argc, char *argv[])
A->data[2][1] = 5;
A->data[2][2] = 0;



B->data[0][0] = 20;
B->data[1][0] = 10;
B->data[2][0] = 0;

mat *x = solve_linear_LU(A, B);
mat *x =solve_linear_LU(A, B);
// mat *x = mat_mul_naive(A,B);
mat_print(x);
mat_free(x);
Expand Down

0 comments on commit ea3cd17

Please sign in to comment.