Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is RHS vector

please I am trying to understand matrix computation. and my question may seem simple but please need an answer can some briefly explain to me what is an RHS vector. I often see it used in the Apache commons math library for example i got this from a stackoverflow page:

public class LinearAlgebraDemo
{
    public static void main(String[] args)
    {
        double [][] values = {{1, 1, 2}, {2, 4, -3}, {3, 6, -5}};
        double [] rhs = { 9, 1, 0 }; /* RHS Vector */

        RealMatrix a = new Array2DRowRealMatrix(values);

        DecompositionSolver solver = new LUDecompositionImpl(a).getSolver();

        RealVector b = new ArrayRealVector(rhs);
        RealVector x = solver.solve(b);

        RealVector residual = a.operate(x).subtract(b);
        double rnorm = residual.getLInfNorm();

    }
}

can someone explain this code to me and especially the RHS vector and its purpose. thank you very much.

like image 239
faisal abdulai Avatar asked Sep 11 '12 22:09

faisal abdulai


2 Answers

You matrix equation looks like this:

Ax = b

where A is a matrix with m rows and n columns, x is a column vector of m unknowns, and b is another column vector (aka The Right-Hand Side) of m known values. It's on the right hand side of the equals sign - hence the name.

If I gave you a simple equation with two numbers and an unknown value x, you'd know exactly how to solve it:

Ax = b -> x = b/A

Think of this as solving for x by multiplying both sides of the equation by the inverse of A.

In this case it's more complicated, because dividing by a matrix means inverting it.

You're not going to invert the matrix; you're going to create something called an LU decomposition of the matrix A. You should read about what that is and why it's better than calculating a full inverse if you're interested.

like image 161
duffymo Avatar answered Sep 22 '22 08:09

duffymo


RHS is a common mathematical abbreviation for "right hand side". Here it appears that you are solving a system of linear equations Ax = b where A is an n x n matrix and x and b are n-dimensional column vectors. If you don't understand this terminology, then I suggest you study up on linear algebra.

As for the code, rhs is an array which is used to initialize the elements of the vector b. Similarly, the 2D array values is used to initialize the elements of the matrix A (actually a reference variable named a).

like image 28
Code-Apprentice Avatar answered Sep 18 '22 08:09

Code-Apprentice