Dividing a matrix by a matrix: Bartlett Correlation Algorithm - algorithm

Is there a library with the inverse function included?
I am currently working on a direction finding algorithm as part of a project. I am using the Bartlett Correlation. In the Bartlett correlation I will need to divide the numerator, which is already 3 matrix multiplications(including Hermitian Transposes), by the denominator which is the product of a matrix and its Hermitian Transpose.
I realize that in order to divide I use the inverse. I am just trying to save time and hoping that there is a library where the inverse is included. I have only found links to source code for finding the inverse. This is only a small portion of the project and I am hoping to save time.
I do have the rest of my code written, but, have not started with the division/inverse yet. So, I will not include that code.

I suggest use an implementation of BLAS, they are generally very versatile language and platform wise and used for building LAPACK as well.

Related

How to generate Hadamard patterns?

I am trying to generate Hadamard patterns from hadamard matrices which look like this.
I was told to use the below equations to generate the matrices.
What I have done thus far
I have already found a way to generate the matrices by resizing hadamard patterns. However, I do not have any idea what the variables x,y,u and v refer and what matrices I am even supposed to loop through after reading this paper. Does anyone have any idea of how to go about implementing such equations and how I can learn to read such equations in the future?

lapack library in codeblocks, boundary value

I am a student from Germany, currently doing the master thesis. In my master thesis, I am writing a Fortran code in code blocks. In my code, I am using some of the LAPACK functions.
I want help regarding adding LAPACK library in code block software. I searched a lot on the internet but I couldn't find anything. It'll be better if you provide me all the source links extension of the previous question.
In my code, I need to solve the following system of equation, {K}{p} = {m}
Where
{K} = Matrix
{p} = vector
{m} = vector
I have all the elements of vector {m} and matrix {K} computed and I have some known values of vector {p}. It's boundary value problem.
Now I want to find out only unknown values of elements of a vector {p}.
Which function should I use?
I went through the LAPACK manual available online but couldn't find.
Well you did not go through the documentation so thoroughly :) You are looking for solvers of a linear equation.
http://www.netlib.org/lapack/lug/node38.html
Please specify a little more about complex/real double/float. ill posed? Over or under determined or quadratic? If quadratic then symmetric or upper triangular? Banded?
There is a hord of different algorithms one would consider. Runtime / stability / convergence behaviour are very different dependent on K. The most stable would be [x]gelsd. It's a divide and conquer algorithm via SVD and gives you with proper conditioning the moore penrose generalised inverse. But it is by far the slowest algorithm too.
btw, http://www.netlib.org/lapack/lug/node27.html, outlines all general solvers.
If you already have some values of your p, you would like to go a different route than a straight forward inversion. You are a lot better off, if you use an iterative method like conjugate gradient least squares problem with regularization. This is discussed in length in Stoer, Bullirsch, Introduction to Numerical Analysis, Chapter 8.7 (The Conjugate-gradient Method of Heestens and Stiefel).
There are multiple implementations online. One you will find in a library I wrote during my PhD: https://github.com/kvahed/codeare/blob/master/src/optimisation/CGLS.hpp

Definition of matrix-vector division operator of Julia

I stumbled upon something, which I consider very strange.
As an example consider the code
A = reshape(1:6, 3,2)
A/[1 1]
which gives
3×1 Array{Float64,2}:
2.5
3.5
4.5
As I understand, in general such division gives the weighted average of columns, where each weight is inversely proportional to the corresponding element of the vector.
So my question is, why is it defined such way?
What is the mathematical justification of this definition?
It's the minimum error solution to |A - v*[1 1]|₂ – which, being overconstrained, has no exact solution in general (i.e. value v such that the norm is precisely zero). The behavior of / and \ is heavily overloaded, solving both under and overconstrained systems by a variety of techniques and heuristics. Whether this kind of overloading is a good idea or not is debatable, but it's what people have come to expect from these operations in Matlab and Octave, and it's often quite convenient to have so much functionality available in a single operator.
Let A be an NxN matrix and b be a Nx1 column vector. Then \ solves Ax=b, and / solves xA=b.
As Stefan mentions, this is extended to underdetermined cases as the least squares solution. This is done via the QR or SVD decompositions. See the details on these algorithms to see why this is the case. Hint: the linear form of the OLS estimator can actually be written as the solution to matrix decompositions, so it's the same thing.
Now you might ask, how does it actually solve it? That's a complicated question. Essentially, it uses a matrix factorization. But which matrix factorization is used is dependent on the matrix type. The reason for this is because Gaussian elimination is O(n^3), and so treating the problem generally is usually not good. But whenever you can specialize, you can get speedups. So essentially \ (and /, which transposes and calls \) check for a bunch of special types and pick a factorization or other algorithm (LU, QR, SVD, Cholesky, etc.) based on the matrix type. The flow chart from MATLAB explains this very well. There's a lot of details here, and it gets even more details when the matrix is sparse. Also IterativeSolvers.jl should be mentioned because it's another set of algorithms for solving Ax=b.
Most applied math problems reduce down to linear algebra, with solving Ax=b being one of the most important and difficult problems, which is why there is tons of research on the subject. In fact, you can probably say that the vast majority of the field of numerical linear algebra is devoted to finding fast methods for solving Ax=b on specific matrix types. \ essentially puts all of the direct (non-iterative) methods into one convenient operator.

Does the polygon intersection code in CGAL always use GMP's rational number library?

I am currently working on determining whether two polygons intersect with each other. I have found an example in CGAL's documentation webpage:
http://doc.cgal.org/latest/Boolean_set_operations_2/Boolean_set_operations_2_2do_intersect_8cpp-example.html
However, this code employs GMP's rational number library hence it is relatively slow. In my problem, I need to determine intersection of polygons for thousands of times. Therefore, I wonder whether there is an alternative which only use the floating-point arithmetic so that it can run much faster?
Thanks a lot.
CGAL states: "CGAL combines floating point arithmetic with exact arithmetic, in order to be efficient and reliable. CGAL has a built-in number type for that, but Gmp and Mpfr provide a faster solution, and we recommend to use them." (1)
Also in my experience that is what CGAL is for, exact computation.
If you use CGAL because it supplies the polygon intersection features directly, maybe an alternative library would be a possibility. Here are some from an alternative thread.
One final thought. You can also speed up your code within CGAL. In your case I would suggest computing the bounding box for every polygon and first do a intersection tests with those. It will already eliminate a lot of polygon pairs.

Ada matrix package

I'm in search for a free package that do most matrix/vector operations. I can write some basic functions myself but for advanced ones like computing eigenvalues and eigenvectors I would prefer robust code and I would like to know if such packages are freely available. If I understand correctly Ada 2005 have more matrix operations facilities but it has a function to calculate the eigenvalues for a symmetric and hermitian matrices only. I'll need a more general packages which can handle any kind of matrix.
An Ada95 matrix package (54KB tar.gz file) from Drexel Fusion Laboratory had the link: http://dflwww.ece.drexel.edu/research/ada/ but the page for this ink is non-existent today.
Thanks a lot...
I think that the Ada95 package you mean is here -- but it's only 35k, and it seems to have less functionality than the Ada2005 standard library does.
Not sure how this Ada95 binding to BLAS came to be in my browser cache! I see that for general matrix solving you need LAPACK too, I wonder whether the bindings already in GNAT will help? Package System.Generic_Real_LAPACK in file s-gerela.ad[bs]. The comments say
-- LAPACK Computational Routines
-- gerfs Refines the solution of a system of linear equations with
-- a general matrix and estimates its error
-- getrf Computes LU factorization of a general m-by-n matrix
-- getri Computes inverse of an LU-factored general matrix
-- square matrix, with multiple right-hand sides
-- getrs Solves a system of linear equations with an LU-factored
-- square matrix, with multiple right-hand sides
-- orgtr Generates the Float orthogonal matrix Q determined by sytrd
-- steqr Computes all eigenvalues and eigenvectors of a symmetric or
-- Hermitian matrix reduced to tridiagonal form (QR algorithm)
-- sterf Computes all eigenvalues of a Float symmetric
-- tridiagonal matrix using QR algorithm
-- sytrd Reduces a Float symmetric matrix to tridiagonal form
which I suspect is a small subset of the full library. Still, could act as a useful springboard for more extensive bindings.
As suggested in John Barnes Rationale for Ada 2005, Ada's Annex G: Numerics is not intended "as a substitute for professional libraries such as the renowned BLAS," but nothing precludes an implementation from using BLAS internally. As a concrete example, the GNAT compiler implements both G.3.1 Real Vectors and Matrices and G.3.2 Complex Vectors and Matrices using BLAS and LAPACK. To see the details, you can examine the relevant package bodies:
$ export ADA_INC = /your/path/to/adinclude
$ view $ADA_INC/$(gnatkr Ada.Numerics.Generic_Real_Arrays.adb)
$ view $ADA_INC/$(gnatkr Ada.Numerics.Generic_Complex_Arrays.adb)
The site at which this package was previously available has been migrated and the old content is now available at:
http://dfl.ece.drexel.edu/content/ada95-matrix-package

Resources