0
$\begingroup$

I have a matrix in Mathematica, which I have built using Normal[SparseArray].

Each entry of this matrix is an equation in one variable. What I need to do is

1) to select some of the entries of the matrix, according to a given pattern

2) for the selected entries, solve the corresponding equations.

Let's suppose that I have the pattern for my chosen entries in a txt.file: concretely, this means that I have saved there the indices of the entries that I want to choose.

EDIT: I'll try my best to post an example. I know that the format is not excellent and please feel free to edit it so that it may look easier to understand, unfortunately I don't know how to do it.

Anyway, here is an example of such a matrix of equations. The latin letters are KNOWN, they just represent known parameters. Instead, the X# letters are UNKNOWNS: they are the variables of the equations. As you can see, if I start from element (6,6), I can extract X10 by solving the equation. Then I can go to element (4,6) and, knowing now the value of X10, I can extract X9....and so on.

The way to proceed through the indices of the matrix is something that I have worked out separately, so you can take that for granted: I have a file where I stored the [i,j] indices of the entries which I am interested in.

    {
  {a (a X1 + b X2) + b (a X2 + b X5), c (a X2 + b X5), d (a X2 + b X5), e (a X3 + b X6) + f (a X4 + b X7),g (a X4 + b X7), h (a X4 + b X7)},
  {a c X2 + b c X5, c^2 X5, c d X5, c e X6 + c f X7, c g X7, c h X7},
  {a d X2 + b d X5, c d X5, d^2 X5, d e X6 + d f X7, d g X7, d h X7},
  {a (e X3 + f X4) + b (e X6 + f X7), c (e X6 + f X7), 
   d (e X6 + f X7), f (f X10 + e X9) + e (e X8 + f X9), 
   g (f X10 + e X9), h (f X10 + e X9)},
  {a g X4 + b g X7, c g X7, d g X7, f g X10 + e g X9, g^2 X10, 
   g h X10},
  {a h X4 + b h X7, c h X7, d h X7, f h X10 + e h X9, g h X10, h^2 X10}
 }
$\endgroup$
4
  • $\begingroup$ Do all the equations need to be solved for the same variables, or does the list of indices include the variable you want to solve for? But I think you want some combination of MapAt and a pure function like Solve[#, x] $\endgroup$
    – Jason B.
    Commented May 10, 2016 at 14:54
  • 3
    $\begingroup$ I am guessing your txt file contains the i,j subscripts of the equations that you want to extract. If that guess is correct then you might look at the documentation for Part and see if you can guess from the examples how to use your txt file to build a Mathematica expression matrix[[{pos1, pos2, pos3,...}]] to extract the desired equations. Then you can pass the resulting list to Solve. If you can provide a simple clear example this should help others understand and more likely give a correct answer on the first try. $\endgroup$
    – Bill
    Commented May 10, 2016 at 18:30
  • $\begingroup$ @Bill: please have a look at my edit: I hope it clarifies your doubts $\endgroup$
    – johnhenry
    Commented May 11, 2016 at 10:49
  • $\begingroup$ @JasonB: there is not only one variable, unfortunately. I hope that from the edit of my post you may be able to understand the structure of the matrix. I guess you are right: perhaps I should write in the input file also the names of the variables... $\endgroup$
    – johnhenry
    Commented May 11, 2016 at 10:50

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.