## Solve Workflow Tutorial

In this section, you are introduced to a system-solving workflow that uses the linear algebra package LAPACK, provided by Finastra.

To solve the system, you choose one of the following methods:

• Cholesky decomposition
• LU decomposition
• QR decomposition
• Singular Value Decomposition

### Template - Solve Workflow

Run the fpp-library_tutorial_Solve configuration.

The result is displayed in fig. 72. It corresponds to the matrix $$x$$ that solves the equation $$Ax = b$$ applying the LAPACK LU decomposition.

### Solve Files

#### Solve Input

The input file includes the matrices $$A$$ and $$b$$ to solve the matrix equation $$Ax = b$$. It also contains the selected method, in this case, the LU decomposition:

{
"documents": [
{
"A": [
[
0.705547511577606,
0.533424019813538,
0.579518616199493,
0.289562463760376,
0.301948010921478
],
[
0.774740099906921,
0.014017641544342,
0.76072359085083,
0.814490020275116,
0.709037899971008
],
[
4.53527569770813E-02,
0.414032697677612,
0.862619340419769,
0.790480017662048,
0.373536169528961
],
[
0.961953163146973,
0.871445834636688,
5.62368631362915E-02,
0.949556648731232,
0.364018678665161
],
[
0.524868428707123,
0.767111659049988,
5.35045266151428E-02,
0.592458248138428,
0.468700110912323
]
],
"b": [
[
0.298165440559387
],
[
0.622696697711945
],
[
0.647821187973022
],
[
0.263792932033539
],
[
0.27934205532074
]
],
"operation": "LU"
}
]
}

#### Solve Workflow and Box

In the workflow, the fpp-library_tutorial_Solve box is called with the request input and the SOLUTION output.

The content of the fpp-library_tutorial_Solve box is displayed below:

// input management
def request(input){
// create a jackson Object mapper
ObjectMapper MAPPER = new ObjectMapper();
// read the input, put it in an ObjectNode node
// extract the document part from node
doc = node["documents"][0]
}

// get matrix A
def heightA = doc.get("A").size()
def widthA = doc.get("A")[0].size()
final double[][] A = new double[heightA][widthA];
for (int i = 0; i < heightA; ++i)
for (int j = 0; j < widthA; ++j)
A[i][j] = doc.get("A")[i][j].doubleValue()

// get matrix B
def heightB = doc.get("b").size()
def widthB = doc.get("b")[0].size()
final double[][] b = new double[heightB][widthB];
for (int i = 0; i < heightB; ++i)
for (int j = 0; j < widthB; ++j)
b[i][j] = doc.get("b")[i][j].doubleValue()

// get the package to use
def operation = doc.get("operation").textValue()

// initialize a Lapack object
final Lapack lapack = getLapack()

//main treatment according to the selected method
switch(operation){
case "CHOLESKY":
//Solves the linear system with a upper Cholesky Decomposition
final double[][] x = lapack.solveCholesky(A, false, b);
output("SOLUTION", x.toString())
break

case "LU":
//Solves the linear system with LU Decomposition without storing the result of the decomposition
final double[][] x = lapack.solveLU(A, b);
output("SOLUTION", x.toString())
break

case "QR":
//Solves the linear system with a reduce QR Decomposition without storing the result of the decomposition
final double[][] x = lapack.solveQR(A, b);
output("SOLUTION", x.toString())
break

case "SVD":
//Solves the linear system with Singular Value Decomposition without storing the result of the decomposition
final double[][] x = lapack.solveSVD(A, b);
output("SOLUTION", x.toString())
break

default:
break
}

### Solve Results

The result displayed in fig. 74 is the output SOLUTION of the system solved by the LAPACK LU decomposition.