Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|cite|improve this question
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)



share|cite|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.