Group Abstract Group Abstract

Message Boards Message Boards

0
|
7.3K Views
|
7 Replies
|
4 Total Likes
View groups...
Share
Share this post:

Convert a system of linear equations to matrix-form

Posted 3 years ago

Is there a simply function in WL which converts some given system eqns of linear equations in vars into the standard matrix form A.x == b ?

As an example: enter image description here

I have such a function but it's non-trivial. It uses the CoefficientList-tensors. I suspect that there must be something better.

POSTED BY: Werner Geiger
7 Replies

For verification, there is LinearFunctionQ in the Wolfram Function Repository. For the actual conversion of equations to matrix-vector, CoefficientArays is the recommended method (that is to say, it's what we use in-house).

POSTED BY: Daniel Lichtblau
Posted 3 years ago

Oh thanks, Daniel. I did not know this LinearFunctionQ. I will examine it.

POSTED BY: Werner Geiger
Posted 3 years ago

Daniel, I examined LinearFunctionQ and found:

  • It handles expressions written with normal symbols x, y, ... correctly
  • It does respect variables written as Indexed (say Indexed[x,1])
  • It does respect variables written as Subscript(ed) (say Subscript[x,1])

Hence your function is perfect (BTW: Is the source code available?).

My code may be overloaded, since it outputs detailed messages to tell the user exactly what is wrong with which equation. For simplicity, I think I'll throw that out and use your function.

Thanks for that hint!

POSTED BY: Werner Geiger

It seems the source code is not available for this particular function.

POSTED BY: Daniel Lichtblau
Posted 3 years ago
POSTED BY: Werner Geiger

You may have a look at CoefficientArrays:

In[1]:= CoefficientArrays[{a + x - y - z == 0, 
   b + x + 2 y + z == 0}, {x, y, z}] // Normal

Out[1]= {{a, b}, {{1, -1, -1}, {1, 2, 1}}}
POSTED BY: Gianluca Gorni
Posted 3 years ago

I Know. I use the CoeffientList-tensors, which are easier to use.

POSTED BY: Werner Geiger
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard