# Assigning variables from rules

**URL:** <https://community.wolfram.com/t/assigning-variables-from-rules/18017>\
**Category:** Questions\
**Tags:** algebra, equation-solving\
**Created:** [April 26, 2021, 3:04am UTC](https://community.wolfram.com/t/assigning-variables-from-rules/18017 "2021-04-26T03:04:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rryan](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/rryan/32/25542_2.png) [@rryan](https://community.wolfram.com/u/rryan)\
**Post date:** [April 26, 2021, 3:04am UTC](https://community.wolfram.com/t/assigning-variables-from-rules/18017/1 "2021-04-26T03:04:01Z")

</div>

I’m new to Mathematica. I have to say, it’s making me crazy. I want to solve a system of four simultaneous equations in four variables and then have the numerical solutions applied to those variables from the rules so that, in this case,

```
m=127, b=7,f=14.5588, t=148.559:

solutions = 
Solve[m == 127 && b == 7 && f == 0.098*t && m + b + f == t, {m, b, f,
t}]

```

Then I want to set m, b, t, and f to the values in the rule assignment. I’ve tried every permutation I can think of of Part and ReplaceAll, but I either get an error or I get m=m, b=b, etc.  
It really shouldn’t be that difficult, it seems like something users would want to do all the time. I see Stack Exchange with obscure code using @@@, and other stuff.  
Is there not just a simple way to solve a set of simultaneous equations and assign the results to the variables in the equations?

---

<div class="post-metadata">

**Author:** ![hdolhaine](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/hdolhaine/32/35924_2.png) [@hdolhaine](https://community.wolfram.com/u/hdolhaine)\
**Post date:** [April 26, 2021, 11:52am UTC](https://community.wolfram.com/t/assigning-variables-from-rules/18017/2 "2021-04-26T11:52:18Z")

</div>

Hi 'Robert,

it is by no means clear what you want to do. Something like this?

```
m = 127;
b = 7;
solutions = Solve[{f == 0.098*t, m + b + f == t}, {t, f}]
{t, m} /. Flatten[solutions]

```

---

<div class="post-metadata">

**Author:** ![neils](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/neils/32/20595_2.png) [@neils](https://community.wolfram.com/u/neils)\
**Post date:** [April 26, 2021, 3:04pm UTC](https://community.wolfram.com/t/assigning-variables-from-rules/18017/3 "2021-04-26T15:04:54Z")

</div>

Robert,

As Hans points out, its not clear exactly what you want, However, if you are asking how to change rules into assignments, you could do:

```
solutions /. Rule -> Set;

```

In Hans’ corrected example, this will make assignments for t and m. HOWEVER, I believe that changing the rules to assignments is bad coding practice in Mathematica. I generally like to make notebooks that can be rerun without clearing the global variables or quitting the kernel. Once t and m are defined, the earlier code that creates your equations will no longer work without a Clear[“Global`\*”] or killing the kernel.

It is preferable to use the results of solving as Hans showed by doing

```
newexpression /. solutions

```

to make the variable assignments locally.

regards,

Neil
