9
$\begingroup$

I have a list

m={a,b,c,d};

How can I insert $==0$ to get list of equations so that the function Solve can take it as an argument?

m={a==0,b==0,c==0,d==0}

How to remove curly brackets to get?

m=a==0,b==0,c==0,d==0
$\endgroup$
8
  • 4
    $\begingroup$ eqs = Thread[Equal[m, 0]] $\endgroup$
    – Syed
    Dec 19, 2022 at 12:45
  • 4
    $\begingroup$ eqs = # == 0 & /@ m $\endgroup$
    – Syed
    Dec 19, 2022 at 13:06
  • 1
    $\begingroup$ The OP could have received many more answers by waiting a bit before accepting an answer. Its a good idea to wait until you have tested answers befor voting them, and wait further 24hours for other answers before accepting the best one, giving time to other people to contribute. $\endgroup$
    – rhermans
    Dec 19, 2022 at 13:32
  • 3
    $\begingroup$ Replace[m, a_ -> a == 0, 1] $\endgroup$
    – Syed
    Dec 19, 2022 at 13:41
  • 1
    $\begingroup$ m /. {List -> List, a_Symbol -> a == 0} $\endgroup$
    – Syed
    Dec 19, 2022 at 13:50

4 Answers 4

7
$\begingroup$

The following

Thread[Flatten /@ (m == Table[0, Length@m])]

MapThread[Equal, {m, Table[0, Length@m]}]

Inner[Equal, m, Table[0, Length@m], List]

Equal @@@ Transpose[{m, Table[0, Length@m]}]

Internal`InheritedBlock[{Equal}, SetAttributes[Equal, Listable];
 m == Table[0, Length@m]]

res

Edit:

About the second part of the question... I don't really understand what you mean. Perhaps the following?

Extract[1]@{a == 0, b == 0, c == 0, d == 0}

res2

$\endgroup$
1
  • 1
    $\begingroup$ Very nice, InheritedBlock is also a resource function from Wolfram research. The possible issues section can be interesting. $\endgroup$ Dec 20, 2022 at 5:45
6
$\begingroup$
eqns = Table[lhs == 0, {lhs, m}]

eqns = Map[EqualTo[0],m]

eqns = Thread[Equal[m, 0]] (* Credit Syed *)

To use as arguments you can do

f[1,2,Sequence@@eqns]
$\endgroup$
2
  • 1
    $\begingroup$ @bmf just updated to address that. $\endgroup$
    – rhermans
    Dec 19, 2022 at 13:26
  • $\begingroup$ yes, just saw that :-) $\endgroup$
    – bmf
    Dec 19, 2022 at 13:28
2
$\begingroup$
m = {a, b, c, d};

Using Cases

Cases[m, x_ :> x == 0]

Using MapAt

MapAt[# == 0 &, All] @ m

Using ReplaceAt (new in 13.1)

ReplaceAt[x_ :> x == 0, All] @ m

All return

{a == 0, b == 0, c == 0, d == 0}

$\endgroup$
2
$\begingroup$
m = {a, b, c, d};

Using Outer and MapApply:

# == 0 & @@@ Outer[List, m]

{a == 0, b == 0, c == 0, d == 0}

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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