Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
convert linear system to matrix

Subject: convert linear system to matrix

From: tawfik tawfik

Date: 7 Mar, 2011 21:34:06

Message: 1 of 3

Hello

is there any command in matlab to convert linear system to matrix ?

example , if i have :
x1 + 2x2 <= 1
x1 + x2 <= 1

i get A= [ 1 2; 1 1]


thank you

Subject: convert linear system to matrix

From: Think two, count blue.

Date: 7 Mar, 2011 21:59:11

Message: 2 of 3

On 11-03-07 03:34 PM, tawfik tawfik wrote:

> is there any command in matlab to convert linear system to matrix ?
>
> example , if i have :
> x1 + 2x2 <= 1
> x1 + x2 <= 1
>
> i get A= [ 1 2; 1 1]

You can use symvar() to get the list of indeterminates (the variables), and
you can use coeffs() to extract the coefficients of particular expressions
with respect to a given variable.
http://www.mathworks.com/help/toolbox/symbolic/coeffs.html

Note that coeffs() returns values in increasing order of polynomial power, and
note for your purpose that 2*x2 is constant with respect to x1 and so would
appear in the first (lowest power) term when the coeffs is used.

You may need to double() the result as the results will generally be symbolic
numbers rather than double precision numbers.

coeffs() without an explicit variable to select _will_ work on the linear
system and return the coefficients for all the variables at once; the
difficulty there is in knowing the order that it has selected. It _probably_
uses "closest to x" ordering described for the second syntax of symvar
http://www.mathworks.com/help/toolbox/symbolic/symvar.html but the order is
not documented.

Subject: convert linear system to matrix

From: tawfik tawfik

Date: 10 Mar, 2011 15:15:09

Message: 3 of 3

thank you very much

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us