### Problem Statement

Consider three reactions for the production of ammonia

1. Steam-reforming of methane
<div style="margin-top:5px;margin-bottom:10px">
CH<sub>4</sub> + H<sub>2</sub>O &rarr; CO + 3 H<sub>2
</div>
2. Water-gas shift 
<div style="margin-top:5px;margin-bottom:10px">
CO + H<sub>2</sub>O &rarr; CO<sub>2</sub> + H<sub>2
</div>
3. Haber-Bosch reaction
<div style="margin-top:5px;margin-bottom:10px">
N<sub>2</sub> + 3 H<sub>2</sub> &rarr; 2 NH<sub>3</sub>
</div>

Determine if it is possible to construct a process for the production of ammonia with no wasted hydrogen and no release of carbon monoxide.

Let's Solve this.

First of all we will construct a matrix where reaction co-effcicent of each process and each molecule will be shown.

| Species         | R<sub>1</sub> | R<sub>2</sub> | R<sub>3</sub> | Net                 |
| :-------------: | :-----------: | :-----------: | :-----------: | :-----------------: |
|                 | &chi;<sub>1</sub> | &chi;<sub>2</sub> | &chi;<sub>3</sub> | $\sum_k\nu_k\chi_k$ |
| CH<sub>4</sub>  | -1            |  0            |  0            | &leq; 0             |
| H<sub>2</sub>O  | -1            | -1            |  0            | &leq; 0             |
| CO              |  1            | -1            |  0            | 0                   |
| H<sub>2</sub>   |  3            |  1            | -3            | 0                   |
| CO<sub>2</sub>  |  0            |  1            |  0            | &geq; 0             |
| N<sub>2</sub>   |  0            |  0            |  1            | &leq; 0             |
| NH<sub>3</sub>  |  0            |  0            |  2            | 1                   |


which includes three equality constraints which need to be solved for
&chi;<sub>1</sub>, &chi;<sub>2</sub>, and &chi;<sub>3</sub>.


```python
# importing sympy and numpy
import numpy as np
import sympy as sm
```


```python
# creating three variables for three reactions
sm.var('r1 r2 r3')
```




    (r1, r2, r3)




```python
# creating dictionary which stores the equation for each substance
v = {}

v['CH4'] = -r1
v['H20'] = -r1 -r2
v['CO'] = r1 -r2
v['H2'] = 3*r1 +r2 -3*r3
v['CO2'] = r2
v['N2'] = -r3
v['NH3'] = 2*r3
```


```python
# balance equations

balance_eqn = [
    sm.Eq(v['NH3'], 1),
    sm.Eq(v['CO'], 0),
    sm.Eq(v['H2'], 0)
]
```


```python
#solving balance equation using sympy
result = sm.solve(balance_eqn)

print(result)
```

    {r1: 3/8, r2: 3/8, r3: 1/2}



```python
# printing the final output of process for given conditions

for molecule in v.keys():
    print(molecule, v[molecule].subs(result))

```

    CH4 -3/8
    H20 -3/4
    CO 0
    H2 0
    CO2 3/8
    N2 -1/2
    NH3 1


Those are the freaction of substances that will be left at the end of the process (basis 1 unit of ammonia), given that all hydorgen and carbon monoxide are consumed.

Reference:
https://nbviewer.jupyter.org/github/jckantor/CBE20255/blob/master/notebooks/02.02-Generation-Consumption-Analysis-for-Ammonia-Production.ipynb


```python

```

cada411533ab3a7e6a92713045016cae82cac323
ipynb
Jupyter Notebook
Generation Consumption Analysis - Basics/generation-consumption-basics.ipynb
galib96/ChemE-with-Python
3cdb42e082d3a9108a5e7a1558a76495ea37674c
Apache-2.0
Generation Consumption Analysis - Basics/generation-consumption-basics.ipynb
galib96/ChemE-with-Python
3cdb42e082d3a9108a5e7a1558a76495ea37674c
Apache-2.0
Generation Consumption Analysis - Basics/generation-consumption-basics.ipynb
galib96/ChemE-with-Python
3cdb42e082d3a9108a5e7a1558a76495ea37674c
Apache-2.0
Qwen/Qwen-72B
1. YES
2. YES