Message Boards Message Boards

How to treat Rule as an equality/equation

Hi guys,

I am trying to solve a set of equations which have matrices (The code for that is at the bottom). Solutions are of this form

{{k[1][2] -> 1 - k[1][1], k[2][2] -> 1 - k[2][1]}}
{{k[1][2] -> -3 + k[1][1], k[2][2] -> 3 + k[2][1]}}

Is there any way I can re-use these solutions to convert them in the form of equations as k[1][2]= 1 - k[1][1], as I intend to use these linear equation further for solving under constraints using Reduce:
Reduce[{Sol1[[1, 1]] && Sol1[[1, 2]] && Sol2[[1, 1]] && Sol2[[1, 2]] && 0.9 <= m11 <= 1.1 && 0.9 <= m22 <= 1.1}, {k[1][1], k[1][2],  k[2][1], k[2][2]}]

but as:  {{k[1][2] -> 1 - k[1][1], k[2][2] -> 1 - k[2][1]}} or {{k[1][2] -> -3 + k[1][1], k[2][2] -> 3 + k[2][1]}}   these are rules not equations, therefore I am unable to solve them automatically by excessing in this way "Sol1[[1, 1]]". Is there any way I can treat these rules -> as equations so that I can further use it for Reduce procedure?
(you can copy paste the bellow code to execute).


POSTED BY: Usman Rauf
4 years ago
In[1]:= rules = {a -> b, {c -> d, e -> f}};
        Equal @@@ Flatten[rules]

Out[1]= {a == b, c == d, e == f}
POSTED BY: Ilian Gachevski
4 years ago
Awsome, thats good. Do it has any upper bound ? or I can convert hundreds or rules into equations using this structure?
POSTED BY: Usman Rauf
4 years ago
how does @@@ it works ? If i put @@ it simply equates the 2 roots of the same list of solutions if I put @ it returns me TRUE, what is the logic and semantic behind using it in three different ways.
POSTED BY: Usman Rauf
4 years ago
You can try replacing Rule->Equal

 a -> 1 /. Rule -> Equal
POSTED BY: Gianluca Gorni
4 years ago

After doing some operation I have a list (named as "final") which have solutions. Some solutions are less then -1*10^(-10) just like below k[1][4] < -1*10^-10.

k[1][1]==24166.7,    k[1][2]==-755.208 ,        k[1][3]==12083.3 ,       k[1][4]==-1.52454*10^-10  ,    k[2][1]==-755.208

I am trying to assign zero "0" to those elements of list which are below a certain values but I am unable to do so using:

For[i = 1, i <= 16,
  i++, {If[final[] <  -1*10^-10, final[]==0]}];

I have also tried using /. rule operation but it is not working. Is there any way I can do it ?

k[1][4] is part of the list "final" so when I say final ==0 it gives me :
(k[1][4] == -1.52454*10^-10) == 0
which is correct but I need to access the part (K[1][4]) of the list
final which is final[[4]] and I need to assign it zero if it is below a certain value. I hope it is clear what i need ?
POSTED BY: Usman Rauf
4 years ago

Group Abstract Group Abstract