For a given system of linear equations in *n* unknowns, there must be *n* equations to form the system. e.g.:

3x+4y+5z=26

5x+6y+10z=47

4x+8y+7z=41

Well, how do you solve this system of linear equations with *n* variables with esProc? First, the system of equations should be written in a standard form, and parameters are filled in a text file. Parameters in the same line are separated with Tab. As listed below:

How to solve systems of linear equations in *n* unknowns by programming? The method of elimination by addition and subtraction is widely used. See the following system of equations:

a_{11}x_{1}+a_{12}x_{2}+a_{13}x_{3}+…+a_{1n}x* _{n}*=a

_{10}

a_{21}x_{1}+a_{22}x_{2}+a_{23}x_{3}+…+a_{2n}x* _{n}*=a

_{20}

a_{31}x_{1}+a_{32}x_{2}+a_{33}x_{3}+…+a_{3n}x* _{n}*=a

_{30}

……

a_{n}_{1}x_{1}+a_{n}_{2}x_{2}+a_{n}_{3}x_{3}+…+a* _{nn}x_{n}*=a

_{n}_{0}

If a_{11 }is not equal to zero, we multiply each term of the first equation simultaneously by a_{21}/a_{11}, subtract the first equation from the second one, then the coefficient of x_{1 }in the second equation becomes zero. If a_{11} equals zero, we need to find an equation in which the coefficient of x_{1} is not zero, and make it the first. In this way, we can eliminate all coefficients of x_{1} in the equations after the first one. See below:

a_{11}x_{1}+a_{12}x_{2}+a_{13}x_{3}+…+a_{1n}x* _{n}*=a

_{10}

0+b_{22}x_{2}+b_{23}x_{3}+…+b_{2n}x* _{n}*=b

_{20}

0+b_{32}x_{2}+b_{33}x_{3}+…+b_{3n}x* _{n}*=b

_{30}

……

0+b_{n}_{2}x_{2}+b_{n}_{3}x_{3}+…+b* _{nn}x_{n}*=b

_{n}_{0}

Now let’s look at the case of b_{22}. In the same method, we continue to eliminate coefficients of x_{2 }in all equations after the second one… We do this continuously until the coefficient of x_{n}_{-1} in the *n*th equation is eliminated. At this point, the system of equations will be like the following:

a_{11}x_{1}+a_{12}x_{2}+a_{13}x_{3}+…+a_{1n}x* _{n}*=a

_{10}

0+b_{22}x_{2}+b_{23}x_{3}+…+b_{2n}x* _{n}*=b

_{20}

0+0+c_{33}x_{3}+…+c_{3n}x* _{n}*=c

_{30 }

……

0+0+0+…+m* _{nn}x_{n}*=m

_{n}_{0}

And we can solve it step by step from the *n*th equation:

x* _{n}*=m

_{n}_{0}/m

_{nn}_{……}

x_{3}=(c_{30}-…-c_{3n}x* _{n}*)/c

_{33}

x_{2}=(c_{30}-b_{23}x_{3}-…-b_{2n}x* _{n}*)/b

_{22}

x_{1}=(c_{30}-a_{12}x_{2}-a_{13}x_{3}-…-a_{1n}x* _{n}*)/a

_{11}

If, during the calculation, zero appears in parameters like a_{11}，b_{22}，c_{33},the system of equations has no solution or infinitely many solutions.

The following shows how to solve a system of linear equations in *n* unknowns with esProc:

A | B | C | D | |

1 | =file(“EquInput.txt”) | =A1.import() | =B1.len() | >result=[0]*C1 |

2 | =B1.((C1+1).(B1.~.field(#))) | |||

3 | for C1-1 | =0 | ||

4 | for A3,C1 | if A2(B4)(A3)!=0 | >B3=B4 | |

5 | break | |||

6 | if B3==0 || A3==C1 | next | ||

7 | =A2(B3) | >A2(B3)=A2(A3) | >A2(A3)=B7 | |

8 | for A3+1,C1 | if A2(B8)(A3)==0 | next | |

9 | for C1+1,A3 | >A2(B8)(C9)-=B7(C9)*A2(B8)(A3)/B7(A3) | ||

10 | for C1,1 | =C1.sum(result(#)*A2(A10)(#)) | ||

11 | if A2(A10)(A10)!=0 | >result(A10)=round((A2(A10)(C1+1)-B10)/A2(A10)(A10),4) | ||

12 | else | >result=”Error” | break | |

13 | =result |

In B1, data is read from the text file; Parameters of the system of equations are transformed into sequence groups in A2:

C1 seeks the number of equations in the system of equations, then the result gets looping execution in A3, and coefficients of x* _{n }*will be gradually eliminated with the method of elimination by addition and subtraction. During looping execution in B4, we look for the first equation in which the coefficient of x

*is not zero from the*

_{k }*k*th equation; if we cannot find one like this, it means that the term cannot get eliminated. Among the code in line 7, move the equation in which the coefficient of x

*is not zero to line*

_{k }*k*. In line 8 and 9, we eliminate coefficients of x

*in equations starting from line k+1.*

_{k}Having done the elimination of every step, we can start to work out solution gradually from the last equation in A10, during which a sequence called result will be used to store solutions. If there is no solution or infinite many solutions, return Error. Considering that there could be errors with double-precision number during computation, the solutions will be kept to four decimal places.

Result can be viewed in A13 after all computations:

If new system of equations is required to be solved:

7x_{1}+2x_{2}+9x_{3}-x_{4}=0

2x_{1}+9x_{2}-x_{4}=0

9x_{1}+11x_{3}-x_{4}=0

x_{1}+x_{2}+x_{3} =1

We only need to modify the EquInput.txt file:

With the same program, we compute and read result in A13.

In addition, list of parameters is unnecessary to be imported from a file. Instead, they can be written directly in esProc. The computing progress is similar to that we’ve explained.