# Function “lsq” on Scilab

I want to get a positive solution "x" for the linear system Ax = b. Is there any function for this?

I did some research and I find a function called "lsq" under scilab, what this function is for?

Thank you.

-
The Scilab Online Help website includes a section on the lsq function. –  Peter Phipps Nov 9 '12 at 21:46

As far as I know, lsq does not deal with linear inequalities such as $x\ge 0$. You can use the linear programming function karmarkar instead. The choice of target function does not matter much; it is natural to maximize $\sum x_i$. If no linear inequalities are provided, the routine automatically imposes $x\ge 0$.

The code below finds a solution to $5x_1-x_3=3$, $x_1-2x_2+3x_3=4$ subject to $x\ge 0$.

Aeq = [5 0 -1 ; 1  -2 3]
beq = [3 4]'
c = [-1 -1 -1]'
xopt = karmarkar(Aeq,beq,c)
print(%io(2),xopt)


returns

0.9102308
0.7818466
1.5511541

-