I'm having trouble using Complex with Dynamic real and imaginary inputs. The inputs come from a matrix of popup menus:
InitA = {
{PopupMenu[Dynamic[a11re], Range[-5,5]] + PopupMenu[Dynamic[a11im], Range[-5,5]] Style["i", Italic], PopupMenu[Dynamic[a12re], Range[-5,5]] + PopupMenu[Dynamic[a12im], Range[-5,5]] Style["i", Italic]},
{PopupMenu[Dynamic[a21re], Range[-5,5]] + PopupMenu[Dynamic[a21im], Range[-5,5]] Style["i", Italic], PopupMenu[Dynamic[a22re], Range[-5,5]] + PopupMenu[Dynamic[a22im], Range[-5,5]] Style["i", Italic]}
};
Using those dynamic inputs, I set the parts of a new matrix equal to those dynamic inputs.
a11 = Complex[Dynamic[a11re], Dynamic[a11im]];
a12 = Complex[Dynamic[a12re], Dynamic[a12im]];
a21 = Complex[Dynamic[a21re], Dynamic[a21im]];
a22 = Complex[Dynamic[a22re], Dynamic[a22im]];
A = {{a11, a12},
{a21, a22}};
For some reason, the matrix A isn't read as 4 complex numbers, but just four inputs of the form Complex[Re, Im]. If I remove the Dynamic[] around the variables when using Complex[], A displays 4 complex numbers in TraditionalForm. Does anyone know about the behavior of Complex that restricts it from using dynamic inputs?
EDIT
Later in the application, Det[A] must be found. Using JM's suggestion for creating the complex numbers in A, with initial inputs of A as:
a11re = 2; a11im = -4; a12re = 2; a12im = 0;
a21re = 3; a21im = 0; a22re = 5; a22im = -3;
a11 = Dynamic[a11re + I*a11im];
a12 = Dynamic[a12re + I*a12im];
a21 = Dynamic[a21re + I*a21im];
a22 = Dynamic[a22re + I*a22im];
Det[A]//TraditionalForm outputs "2-4i5-3i-23", which is (2-4i)(5-3i)-(2)(3) without the parenthesis. Why would it not evaluate the determinant fully? That just doesn't make sense to me.
Dynamic[a11re + I a11im].Complexrequires explicit numbers (i.e. satisfiesNumberQ[]). – J. M.'s missing motivation Jun 20 '16 at 16:16- As you receive help, try to give it too, by answering questions in your area of expertise.
- Take the tour and check the faqs!
- When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign!
– Jun 20 '16 at 16:361is a number and can be used everywhere where a number is expected.Dynamic[1]is not a number and cannot be used in such places.Dynamic[expr]is a way to displayexprand automatically recompute it any time a subpart changes. Things wrapped inDynamiccannot be used for computation. If it's a determinant you want to display and update dynamically,Dynamicmust appear once, wrappingDet. – Szabolcs Jun 20 '16 at 18:02