# Dynamic matrix multiplication

I have the following problem:

I want to multiply two matrices and sum them to another matrix C. A.B+ 2B Easy! The matrix A varies as a function of three inputs a,b and c. The second matrix, B, is a 2x2 identity matrix.

here is the code

     Grid[{{"a", "b", "c"},
{InputField[Dynamic[a], FieldSize -> 1],
InputField[Dynamic[b], FieldSize -> 1],
InputField[Dynamic[c], FieldSize -> 1]}}]

A = {{Dynamic[a]*Dynamic[b], 0}, {0, Dynamic[c]}};
B = IdentityMatrix;
A.B + 2 B


Let's say a=c=10 and b=2.

Result

But I don't want to get 10 2+2 and 10+2, I need 22 and 12! It just shows the value of a and c without multiplying.

Using

A = {{Dynamic[a*b], 0}, {0, Dynamic[c]}};


A = {{Dynamic[a]*Dynamic[b], 0}, {0, Dynamic[c]}};


solves the first problem. I got 20+2 and 10+2, which is good but not enough.

It seems that it not possible to simplify operation when using Dynamic... How can I solve the problem? Thx!

The Dynamic should wrap the expresion you want to display. In your case it's the last line:

Clear[a,b,c];
Grid[{{"a", "b", "c"}, {InputField[Dynamic[a], FieldSize -> 2],
InputField[Dynamic[b], FieldSize -> 2],
InputField[Dynamic[c], FieldSize -> 2]}}]

A = {{a*b, 0}, {0, c}};
B = IdentityMatrix;
Dynamic[A.B + 2 B]


Thank you for the answer. I've applied the solution to the real problem and it worked! Now it will be easier to find errors in that!

Avz[\[Theta]z_,
dz_] := {{Cos[\[Theta]z], -Sin[\[Theta]z], 0, 0}, {Sin[\[Theta]z],
Cos[\[Theta]z], 0, 0}, {0, 0, 1, dz}, {0, 0, 0, 1}};

Avx[\[Theta]x_,
dx_] := {{1, 0, 0, dx}, {0, Cos[\[Theta]x], -Sin[\[Theta]x],
0}, {0, Sin[\[Theta]x], Cos[\[Theta]x], 0}, {0, 0, 0, 1}};

Linea[tz_, dz_, tx_, dx_] := Avz[tz, dz].Avx[tx, dx];

Print[Grid[
{
{"", "Theta", "d", "Alpha", "a"},
InputField[Dynamic[d1], FieldSize -> 2],
InputField[Dynamic[alpha1], FieldSize -> 5],
InputField[Dynamic[x1], FieldSize -> 2]},
InputField[Dynamic[d2], FieldSize -> 2],
InputField[Dynamic[alpha2], FieldSize -> 5],
InputField[Dynamic[x2], FieldSize -> 2]},
InputField[Dynamic[d3], FieldSize -> 2],
InputField[Dynamic[alpha3], FieldSize -> 5],
InputField[Dynamic[x3], FieldSize -> 2]},