Git Product home page Git Product logo

vandermonde's Introduction

Vandermonde

What's a Vandermonde matrix?

A Vandermonde matrix is a square matrix that satisfies

a_ij = x_i ^ (j − 1)
a_ij = x_j ^ i
a_ij = x_i ^ (n − j)

Usually what you want is the first form, i.e.

[1 x x^2 x^3 ... x ^ (n - 1)]
[1 y y^2 y^3 ... y ^ (n - 1)]
...
[1 s s^2 s^3 ... s ^ (n - 1)]

Importing

import "github.com/AnthonyHewins/vandermonde" 

Usage

Generally, what you want is this:

Standard Vandermonde:

my_data := []float64{1,2,3}
matrix, err := vandermonde.Vandermonde(my_data, 0, 0)

// matrix = [1 1 1]
//          [1 2 4]
//          [1 3 9]

Transposed version:

my_data := []float64{1,2,3}
matrix, err := vandermonde.Vandermonde(my_data, 0, 1) // axis=1, similar to pandas and other data science langs

// matrix = [1 1 1]
//          [1 2 3]
//          [1 4 9]

// Note: the returned data is a gonum *mat.Dense, so you can also
// do matrix.T() if you need both the matrix and its transpose.

Starting with a different exponent:

my_data := []float64{1,2,3}
matrix, err := vandermonde.Vandermonde(my_data, 2, 0)
// matrix = [1  1  1]
//          [4  8 16]
//          [9 27 81]

my_data := []float64{1,2,3}
matrix, err := vandermonde.Vandermonde(my_data, -1, 0)
// matrix = [1   1 1]
//          [1/2 1 2]
//          [1/3 1 3]

For more advanced usage when you only a slice of the Vandermonde matrix, which can be larger or smaller:

my_data := []float64{1,2,3}

// start with exponent 2, generate 4 terms (instead of 3), default axis
matrix, err := vandermonde.VandermondeWindow(my_data, 2, 4, 0)
// matrix = [1  1  1   1]
//          [4  8 16  32]
//          [9 27 81 243]


// start with exponent -1, generate only 1 row, transposed axis
matrix, err := vandermonde.VandermondeWindow(my_data, -1, 1, 0)
// matrix = [1 1/2 1/3]

vandermonde's People

Contributors

anthonyhewins avatar

Stargazers

 avatar

Watchers

 avatar  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.