# Issue with replacement rules screwing up a matrix [closed]

I am pretty new to using Mathematica as more than a calculator. Essentially my problem is that I am trying to calculate a quantity vector quantity

$x=x_0 - A^{-1}F(x_0)$

where $x_0$ is a 3-entry column vector (of numbers), $A^{-1}$ is the inverse of a 3x3 matrix of functions of three variables, and $F$ is a column vector of three functions of the same three variables. Clearly in order to get a numerical result I need to multiply $A^{-1}$ and $F$ together and replace the three variables with numerical values.

I tried doing it like

x=x_0 - ((AIinv * F)/.{x_1->1, x_2->1, x_3->1})


where those numerical values for the variables are just some that I made up just now. The thing is that when I apply the replacement rules the term (AInv * F) loses its matrix form and turns into a "multidimensional array", which prevents me from subtracting it from $x_0$. In order to fix it I have tried applying MatrixForm[] and Flatten[] and the two in combination to the (AInv*F) term but it does not help. It seems like this would all work great if this wasn't happening. I would appreciate anybody's help!! Thanks much

• x_0 gives (0). Consider renaming it as x0. – thedude Feb 11 '16 at 4:40
• it's actually x{sub}0 with the build in typesetting (on my mac it's control hyphen) – Ern Feb 11 '16 at 4:42
• The proper syntax is Subscript[x, 0], but still try renaming all as x1, x2 etc. – thedude Feb 11 '16 at 4:43
• It might be easier for us to help if you copy the definitions of F and A1inv into your post. In addition, while x_0 can be interpreted as Subscript[x,0], it's better if you post code in completely correct Mathematica code format, so that potential answerers on this site can copy and paste your code into their own copies of Mathematica, facilitating quick answers. – march Feb 11 '16 at 4:53
• You will want to have a close look at documentation for Dot (used e.g. for matrix-times-vector) and also MatrixForm. That latter is a wrapper for formatting and will change the Head from List to MatrixForm, which will make further computation difficult. – Daniel Lichtblau Feb 11 '16 at 15:30

I made up matrices for demonstration. You should use your own.

A = x1 x2 x3 RandomReal[1, {3, 3}];
f = RandomReal[1, 3];
func [x0_] = x0 - LinearSolve[A, f] /. {x1 -> 1, x2 -> 1, x3 -> 1};

MatrixForm@func[1]


Edited after J.M. pointed out that I omitted a dot.

• This helped me greatly. Also I changed the formatting from the graphical matrices made using the palette to ones of the form {{}{}{}}. Everything is working now, thanks! – Ern Feb 11 '16 at 15:32
• That should probably be Inverse[A].f, but in practice, LinearSolve[A, f] is the preferred route. – J. M.'s technical difficulties Feb 11 '16 at 18:08