Purchase Solution

# Matlab -- Developing 22 Independent Material balances and solving in Matlab

Not what you're looking for?

Please see the attached file for the fully formatted problem(s).
Find composition and flow rates from mass percent data.

Here's what the 22 independent material balances should supposedly look like:

1. W1 - W2 -W3=0
2. H1 - H2 - H3 = 0
3. S1 - S2 - S3 = 0
4. H2 - H4- H5 = 0
5. W2 - W5 = 0
6. S2-S5 = 0
7. W5-W7=0
8. S5-S7 = 0
9. H5-H7=0
10. G6-G7=0
11. W3+W7-W8=0
12. H3+H7-H8=0
13. G7-G8=0
14. S3-S8+S7=0
15. -0.685H2+H4=0
16. W1+H1+S1=7500
17. -0.42H5 + G6=0
18. 0.38W1-0.62H1-0.62S1=0
19. -0.05W1-0.05H1+0.95S1=0
20. 0.38W2-0.68H2-0.68S2=0
21. -0.05W2 -0.05H2+0.95S2 =0
22. 0.021W8+0.021H8+0.021S8-0.979G8=0

And here are the answers (composition and flow rates? Which is which?)
x =

1.0e+003 *

4.6500
2.2759
2.3741
2.2759
2.2759
4.6500
2.4750
1.0945
1.3805
0.7497
0.3448
0.3448
1.7253
0.3750
0.1774
0.1976
0.1774
0.1774
0.3750
0.1448
0.1448
0.1448

And here are the variables set up in Excel. Matrix A will be all the coefficients on the left-hand side of the material balances (columns W1-G8) and Matrix B will be the right-hand side of the material balances (the column called 'Ans'). Then we solve for x by x=inv(a)*(b).

W1 W2 W3 W5 W7 W8 H1 H2 H3 H4 H5 H7 H8 S1 S2 S3 S5 S7 S8 G6 G7 G8 Ans
1 -1 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 1 -1 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 1 -1 -1 0 0 0 0 0 0 0
0 0 0 0 0 0 0 1 0 -1 -1 0 0 0 0 0 0 0 0 0 0 0 0
0 1 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0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 0
0 1.0000 0 -1.0000 0 0 0
0 0 0 0 0 0 0
0 0 0 1.0000 -1.0000 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 1.0000 0 1.0000 -1.0000 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
1.0000 0 0 0 0 0 1.0000
0 0 0 0 0 0 0
0.3800 0 0 0 0 0 -0.6200
-0.0500 0 0 0 0 0 -0.0500
0 0.3800 0 0 0 0 0
0 -0.0500 0 0 0 0 0
0 0 0 0 0 0.0210 0

Columns 8 through 14

0 0 0 0 0 0 0
-1.0000 -1.0000 0 0 0 0 0
0 0 0 0 0 0 1.0000
1.0000 0 -1.0000 -1.0000 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 1.0000 -1.0000 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 1.0000 0 0 1.0000 -1.0000 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
-0.6850 0 1.0000 0 0 0 0
0 0 0 0 0 0 1.0000
0 0 0 -0.4200 0 0 0
0 0 0 0 0 0 -0.6200
0 0 0 0 0 0 0.9500
-0.6800 0 0 0 0 0 0
-0.0500 0 0 0 0 0 0
0 0 0 0 0 0.0210 0

Columns 15 through 21

0 0 0 0 0 0 0
0 0 0 0 0 0 0
-1.0000 -1.0000 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
1.0000 0 -1.0000 0 0 0 0
0 0 0 0 0 0 0
0 0 1.0000 -1.0000 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 1.0000 -1.0000
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 1.0000
0 1.0000 0 1.0000 -1.0000 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 1.0000 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
-0.6800 0 0 0 0 0 0
0.9500 0 0 0 0 0 0
0 0 0 0 0.0210 0 0

Column 22

0
0
0
0
0
0
0
0
0
0
0
0
-1.0000
0
0
0
0
0
0
0
0
-0.9790

b =

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
7500
0
0
0
0
0
0

x =

1.0e+003 *

4.6500
2.2759
2.3741
2.2759
2.2759
4.6500
2.4750
1.0945
1.3805
0.7497
0.3448
0.3448
1.7253
0.3750
0.1774
0.1976
0.1774
0.1774
0.3750
0.1448
0.1448
0.1448

##### Solution Summary

The composition and flow rate of a feed stream is calculated using Matlab. The 22 independent material balances and solving in Matlab are developed.

##### Solution Preview

The values in x that you have are

W1

W2

W3

W5

W7

...

G6

G7

G8

]

which are the entries in the heading of your table except the last column. All these entries are in kg/hr.

How do you solve this problem:

You have 4 component flowrates per stream. You have 8 streams so you have a maximum of 32 unknowns. You know that streams 1,2,and 3 do not have glue, thus you set the flowrate of this component in these streams to zero and you are left with 29 unknowns. You also know that stream 4 is pure water so you set the flowrates of the other components to zero. You are left with 26 unknowns. You also know that stream 5 does not have glue so one more unknown out, you're left with 25 unknowns. You know that stream 6 is pure glue so you have three other flowrates as zero, thus you are left with 22 ...