Note: I only have 6 equations shown here, but actually it's 50 equations.

I want to 1) extract the coefficients of every equation and 2) put them in a 50x50 matrix (to get a nice coefficient matrix for this linear system) on the right position, which is indicated by the number behind the name of the variable. For example:

ba5 means that I want to fill the 5th row of the matrix. ba4 is the 4th column, ba7 is the 7th column, ba42 is the 42th. So in the 4th column the coefficient 0.4164... should be copied and in the 7th the coefficient 0.3479..and so on.

Here it is row 6 I want to fill. But this time it should copy the coefficients to the 8th(ba8), 4th(ba4),7th(ba7) and 44th(ba44) column.

Additionally I need to copy the independent variable (in this case ba5 and ba6) on the right side of the equation and the constant to the left side to get a system in the form of A*x=y with A as my 50x50 matrix, x as my vector of ba's (ba4, ba5,ba7 asf) and y as my constants (255.587 in the first equation and 6.80 in the second).

Right now, my brain is a little bit messed up and I hope you guys can understand what I mean. If not, please ask.

I think this is a duplicate of the question linked above, with the addition that you should use = in the equations. Instead, have the right hand side of each of them (corresponding to ba1, ba2, ... respectively) in a list. Then use that list, together with the list of symbols {ba1, ba2, ...} in the method described in the linked answer.
–
SzabolcsFeb 4 '14 at 18:24

Thanks @Szabolcs, the link helps me out. But what about the constant, i.e the number without a variable. In every equation it is on another position. Somehow I have to isolate this one and put it on the other side of the equation, or a least isolate it.
–
holisticFeb 4 '14 at 18:47

If you will include your full list of equations I will provide you with a method to do what I believe you are asking for.
–
Mr.Wizard♦Feb 4 '14 at 19:22

1

@holistic The answer I linked is still usable for your purposes. Suppose your set of equations is $x=x+y+1$ and $y=x-y+2$. Then the command to use is CoefficientArrays[{x + y + 1, x - y + 2}, {x, y}] which gives a list of the form {b,a}. b are the constants and a is the coefficient matrix.
–
SzabolcsFeb 4 '14 at 21:16

1 Answer
1

There are complications to this question (more specifically your data) that are not present in the proposed duplicate, so I wish to address them. First, your data uses Set so e.g. ba5 will be assigned a value, and every time this Symbol appears that value will be substituted. We need to prevent that, so first I will Import the data in a held form, then replace Set with Rule for later manipulation.

We then need to extract all the variables. Although in this case you have in order a line for each variable that appears in the polynomials let me show you how to order these otherwise. That will also let me create a mapping between Symbol names and their numeric labels.

I am not certain of the format of the array that you want as your variable names go up to 47 yet there are gaps (as you comment there are 41 total). Also, I shall make assumptions about how you want the constant values (e.g. 255.587802741733) handled. Nevertheless, we are ready to proceed to extracting the coefficients:

The second array is the main output that you want. It is a 41x41 array with no gaps for "missing" variable numbers such as 11, and 12. You can display it with the numeric labels that we extracted above as follows:

I really am glad to have joined this forum, I can learn a lot, thank you very much!! The uncontinuous numbering is because the numbers represent so called Brodmann brainareas (e.g. 17 is the visuell cortex) and 11,12 were left out in my other programm I used to generate the equations. So your assumptions are helpful, because they keep the "natural numbering" This made it much more tricky. Thanks again :)
–
holisticFeb 5 '14 at 13:17

Mathematica is a registered trademark of Wolfram Research, Inc. While the mark is used herein with the limited permission of Wolfram Research, Stack Exchange and this site disclaim all affiliation therewith.