Tutorial:JMathLab/Equations (Linear Systems)

From HandWiki

Systems of Linear Equations

Solving systems of linear equations is accomplished by either the function linsolve(A,b), or linsolve2(A,b) (LAPACK). In both cases A is the quadratic matrix of the system of equations, and b a (row or column) vector representing the right-hand-side of the equations. The equations may be written as $A\cdot z = b$ and we solve for $z$.

<jc lang="math"> A=[2 3 1; 4 4 5; 2 9 3]; b=[0;3;1]; a=linsolve(A,b) printf('%f\n',a)

% a=linsolve2(A,b) % for JLAPAC % printf('%f\n',a) </jc>

For large numeric matrices one should use the LAPACK-version if available. The Jasymca version can also handle matrices containing exact or symbolic elements. To avoid rounding errors in these cases it is advisable to work with exact numbers if possible:

<jc lang="math"> syms x,y A=[x,1,-2,-2,0;1 2 3*y 4 5;1 2 2 0 1;9 1 6 0 -1;0 0 1 0] printf('%f\n',A) b = [1 -2 3 2 4 ]; a=trigrat( linsolve( rat(A), b) ) printf('%f\n',a) </jc>