Git Product home page Git Product logo

ex_matrix's Introduction

ExMatrix

Elixir Hex.pm Read the Docs License

ExMatrix is a new Matrix library for Elixir. This library helps you to create a matrix, manipulate it with values and add/subtract two matrices.

What is a Matrix

A matrix is a collection of numbers arranged into a fixed number of rows and columns.

Here is an example of a 3x2 matrix which means that we have 3 rows and 2 columns.

        col 1  col 2
row 1 |  0      1   |
row 2 |  2      7   |
row 3 |  9      0   |

This is row 2

|  2      7   |

This is col 2

  col 2
|   1   |
|   7   |
|   0   |

To get value from the above matrix we need to specify the row and colum that we need to get the value from. The known syntax is (number_of_rows,number_of_columns) (0,1) = 1 and (2,0) = 9

Installation

First, add ExMatrix to your mix.exs dependencies:

def deps do
  [
    {:ex_matrix, "~> 0.1.0"}
  ]
end

Then, update your dependencies:

$ mix deps.get

Elixir Matrix

So to generate an elixir matrix you can use ExMatrix.create("RowsxColumns") will generate a map that can be used as a matrix

But note that ExMatrix.create(...) will generate an empty matrix as you can see in the example

  iex> matrix = ExMatrix.create("3x2")
  %{"0" => %{"0" => "", "1" => ""},
    "1" => %{"0" => "", "1" => ""},
    "2" => %{"0" => "", "1" => ""}
  }

So to fill this matrix with values you can use ExMatrix.set_matrix(matrix,data)

  matrix = %{"0" => %{"0" => "0", "1" => "1"},
             "1" => %{"0" => "2", "1" => "7"},
             "2" => %{"0" => "9", "1" => "0"}
            }

Now you can get values matrix["0"]["1"] = 1 and matrix["2"]["0"] = 9.

Adding or Subtracting two matrices

There are many operation that you can apply on matrices and one of these operations is to add and subtract two matrices.

Small review on how we deal with addition and subtraction of two matrices:

   Matrix A     +      Matrix B     =     Result 
|  0      1   |   |  1      -1   |   |  1      0   |
|  2      7   |   |  7      -2   |   |  9      5   |
|  9      0   |   |  -1      8   |   |  8      8   |

You can use ExMatrix.add_matrices(matrix_1,matrix_2) or ExMatrix.sub_matrices(matrix_1,matrix_2)

Example Function

In case that there is something vague please use a helper function

  iex> ExMatrix.example("2x2")
  %{"0" => %{"0" => "(0,0)", "1" => "(0,1)"},
    "1" => %{"0" => "(1,0)", "1" => "(1,1)"}
  }

What's Next

This library will be extend to have the ability to:

  1. Add or subtract two or more matrices
  2. Multiply and Divide two or more matrices
  3. Matrix Transpose

For contribution on GitHub

Please read the contribution requirements before start working

Copyright and License

Copyright (c) 2018, Jad Tarabay.

ExMatrix source code is licensed under the MIT License.

ex_matrix's People

Contributors

jat10 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.