0

I have a solution list as below from solving a linear equation system:

w[2, 2] -> 0.0000183294,
w[2, 3] -> 0.0000296603,
w[2, 4] -> 0.0000233449,
w[3, 2] -> 0.0000230831,

When I call, for example: w[3,2] I get w[3,2] as output instead of 0.0000230831.

How can I assign these answers to a 2D array named so W[i,j] such that I can call them by their indices?

4

1 回答 1

1

Solution lists are replacement rules and to get them to work you have to apply the rules. Lets say that you have a Solve[] statement that produces your solution list, the following will create a function W[i,j] that will return the value of w[i,j] if it exists in the list.

sol = Solve[...];
W[i_, j_] := w[i, j] /. sol

As an aside, you should understand that single brackets F[i,j,...] denote a function of the variables i, j, ... and double brackets F[[i,j]] denote a 2D array with indexes i and j. In general it is faster and better to use replacement lists to build functions than it is to make arrays out of them.

于 2013-05-26T10:37:58.823 回答