3
$\begingroup$

hi i am just trying to create a matrix depending on some specific conditions for which i designed these codes which work fine but i want to concise these codes.

EEV1 = Log[EV1]/(2*\[A]);
EEV2 = Log[EV2]/(2*\[A]);
EEV3 = Log[EV3]/(2*\[A]);
EEV4 = Log[EV4]/(2*\[A]);
If[Im[EEV1] > 0 && Im[EEV2] > 0 && Im[EEV3] < 0 && Im[EEV4] < 0, 
Fpmat = Transpose[{EVEC1, EVEC2}] ];
If[Im[EEV1] < 0 && Im[EEV2] > 0 && Im[EEV3] > 0 && Im[EEV4] < 0, 
Fpmat = Transpose[{EVEC2, EVEC3}] ];
If[Im[EEV1] < 0 && Im[EEV2] < 0 && Im[EEV3] > 0 && Im[EEV4] > 0, 
Fpmat = Transpose[{EVEC3, EVEC4}] ];
If[Im[EEV1] > 0 && Im[EEV2] < 0 && Im[EEV3] > 0 && Im[EEV4] < 0, 
Fpmat = Transpose[{EVEC1, EVEC3}] ];
If[Im[EEV1] > 0 && Im[EEV2] < 0 && Im[EEV3] < 0 && Im[EEV4] > 0, 
Fpmat = Transpose[{EVEC1, EVEC4}] ];
If[Im[EEV1] < 0 && Im[EEV2] > 0 && Im[EEV3] < 0 && Im[EEV4] > 0, 
Fpmat = Transpose[{EVEC2, EVEC4}] ];

If[Im[EEV1] > 0 && Im[EEV2] > 0 && Im[EEV3] > 0 && Im[EEV4] < 0, 
Fpmat = Transpose[{EVEC1, EVEC2}] ];
If[Im[EEV1] > 0 && Im[EEV2] > 0 && Im[EEV3] < 0 && Im[EEV4] > 0, 
Fpmat = Transpose[{EVEC1, EVEC2}] ];
If[Im[EEV1] < 0 && Im[EEV2] > 0 && Im[EEV3] > 0 && Im[EEV4] > 0, 
Fpmat = Transpose[{EVEC2, EVEC3}] ];
If[Im[EEV1] > 0 && Im[EEV2] < 0 && Im[EEV3] > 0 && Im[EEV4] > 0, 
Fpmat = Transpose[{EVEC1, EVEC3}] ];
If[Im[EEV1] > 0 && Im[EEV2] > 0 && Im[EEV3] > 0 && Im[EEV4] > 0, 
Fpmat = Transpose[{EVEC1, EVEC2}] ];


If[Im[EEV1] < 0 && Im[EEV2] < 0 && Im[EEV3] < 0 && Im[EEV4] < 0, 
Print["choose another value of variable"] Break[]];
If[Im[EEV1] > 0 && Im[EEV2] < 0 && Im[EEV3] < 0 && Im[EEV4] < 0, 
Print["choose another value of variable"] Break[]];
If[Im[EEV1] < 0 && Im[EEV2] > 0 && Im[EEV3] < 0 && Im[EEV4] < 0, 
Print["choose another value of variable"] Break[]];
If[Im[EEV1] < 0 && Im[EEV2] < 0 && Im[EEV3] > 0 && Im[EEV4] < 0, 
Print["choose another value of variable"] Break[]];
If[Im[EEV1] < 0 && Im[EEV2] < 0 && Im[EEV3] < 0 && Im[EEV4] > 0, 
Print["choose another value of variable"] Break[]];

let me see who can help me. Thanks in advance.

$\endgroup$
  • $\begingroup$ Use Which? $\endgroup$ – MarcoB Apr 6 '16 at 16:19
  • $\begingroup$ i just want to reduce the size, by using which its size remains same. $\endgroup$ – M.M Umber Apr 6 '16 at 16:20
  • 2
    $\begingroup$ The logic of your problem sets the size of your conditions, not the syntax. You could see if logically you can exclude some cases. For instance, would there be a single condition that would make any combinations of value containing that condition unacceptable? That could be tested separately as a catch-all condition. Is there a simple combination of choices describing an operation (e.g. an even/odd number of positive imaginary parts, etc)? Can you describe the logic of your choices? $\endgroup$ – MarcoB Apr 6 '16 at 16:31
  • $\begingroup$ EEV1,EEV2,EEV3 and EEV4 represent the eigenvector of 4 different matrices. if the imaginary part of these matrices eigenvector are positive than there eigenvalues crossponding to positive imaginary valued matrix will be used as a new matrix. $\endgroup$ – M.M Umber Apr 6 '16 at 16:39
5
$\begingroup$

You could do :

 Fpmat =
     Switch[Sign[Im[{EEV1,EEV2,EEV3,EEV4}]],
      {1, 1, _, _}, Transpose[{EVEC1, EVEC2}],
      {1, -1, 1, _}, Transpose[{EVEC1, EVEC3}],
      {1, -1, -1, 1}, Transpose[{EVEC1, EVEC4}],
      {-1, 1, 1, _}, Transpose[{EVEC2, EVEC3}],
      {-1, 1, -1, 1}, Transpose[{EVEC2, EVEC4}],
      {-1, -1, 1, 1}, Transpose[{EVEC3, EVEC4}],
      {_, _, _, _}, Print["choose another value of variable"]; Fpmat
      ]

The first case that matches is applied, then Mathematica exit the Switch

The case of equality to 0 may not be what you want.

$\endgroup$
3
$\begingroup$

The number of different actions that can result from the various conditions is much smaller than the number of conditions. What you have to do is collect all the conditions leading to identical actions, and then combine these conditions with Or (written usually as ||). That's all there is to it. I'll leave the typing to you.

$\endgroup$
2
$\begingroup$

How about defining:

f[{ 1,  1,  _,  _}] := Transpose[{EVEC1, EVEC2}]
f[{-1,  1,  1,  _}] := Transpose[{EVEC2, EVEC3}]
f[{ 1, -1,  1,  _}] := Transpose[{EVEC1, EVEC3}]
f[{-1, -1,  1,  1}] := Transpose[{EVEC3, EVEC4}];
f[{ 1, -1, -1,  1}] := Transpose[{EVEC1, EVEC4}];
f[{-1,  1, -1,  1}] := Transpose[{EVEC2, EVEC4}];
f[_] := Print["choose another value of variable"]

Then use:

f[Sign[Im[{EEV1, EEV2, EEV3, EEV4}]]]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.