Posted by

aschunkjava on August 27, 2007 at 2:12 PM PDT

# LinAlg API: Scope, Features, Whichlist

In my previous Blogs on LinAlg API i already received some nice compliments and also some thoughtful advises. Both were helpful in development and help me understand the need and requirements of the community. Therefore i would like to thank you anyone who gave advise and or suggestions.

Baering all this in mind i have fixed some Bugs and added the missing features of this API. As i have written in my headline, this is Milestone 1 of LinAlg which means that development of this API will continue, no matter if and where it will be used in the final end.

Since LinAlg is released under GPL 2 you are free to redistribute, copy and use it as you which. So any help from the community to improve this API and its features is welcome. You do not need to be a Math professional to implement such an API. What you need is programming skills and a good reference book for Math on linear Algebra.

## Features

Last time i have already outlined the features of the missing Matrix class and the Vector implementation. Today and over the week end i have extended the Matrix class so it can work with 3D Vectors.

Besides the basic Matrix operations i have outlined before the Matrix class now offers the following features:

For example its possible now to mulitply a Matrix by a 3D Vector and to create a Matrix from a 3D Vector. This also required a redesign of the Vector3D class so the Matrix class can work with it.

Also i have added further Constructors so it is possible to create different kind of Matrices.

The following examples show what you can do with LinAlg Milestone 1:

` `**Vector3D x = new Vector3D(1,3 ,4);**

Vector3D y = new Vector3D(2, 4, 1);

Vector3D t = new Vector3D(1, 1, 1);

Vector3D u = x.add(y);

Vector3D z = x.add(y).add(t).scalarMul(2);

Matrix m = new Matrix(z);

Matrix k = new Matrix(3, 2, 3, 1);

double det = k.det();

double det2 = m.det();

Matrix l = m.vectorMul(x);

One thing thats nice is - because all methods return references of the specific type - that you can concatenate methods as in this example where you can add three Vectors in a single line:

` Vector3D z = x.add(y).add(t).scalarMul(2);`

In this line you add Vectors **x, y, t** and multiply the result by 2 given the Vectors specified above. The result is **[8.0 16.0 12.0]**.

Another thing you can do is to calculate the **Determinant** of a Matrix:

` `

Matrix m = new Matrix(z);

Matrix k = new Matrix(3, 2, 3, 1);

double det = k.det();

double det2 = m.det();

Matrix l = m.vectorMul(x);

In this example you have two Matrices. The first is created by the Vector z from the example above. The second is a simple 2x2 Matrix. The next two lines determine the **Determinant** using the following formula: **det(A) = m11*m22-m21*m12**.

In the last line Matrix **l** is multiplied by Vector **x**.

Of course the examples above only show only a fraction of LinAlg fetures. You can also **rotate** a Matrix around the three Axes by a specified angle. For example you can rotate a Matrix first around X-Axis, then around Z-Axis and finally around Y-Axis:

` Matrix p = m.RotX(30).rotZ(10).RotY(20);`

This is, again, possible because the methods return references of type Matrix.

## LinAlg API: Code organization

To give LinAlg a more professional look and feel and organization of the code i have reorganized the package structure. With LinAlg API Milestone 1 the classes mentioned before are now hold into a seperate package with a corresponding name. So the Matrix class is hold in a package named **matrix** and the Vector classes are hold in a package named**Vector**.

## License

LinAlg API Milestone 1 is published under GPL version 2.

## Todo

Since the scope of LinAlg API is - compared to other APIs mentioned before - rather narrow and more general the Todo list of LinAlg is not so long as of other APIs offering similar features. However one or another feature will sure show up in the Todo list so stay tune for updates.

LinAlg API Milestone 1 will be available at linalg.dev.java.net .