{
 "metadata": {
  "name": "",
  "signature": "sha256:829300ed441b0056de124b3c59bbb1f7034cd4f5704a4d95b4ff6c77357fd0c5"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 6 :  Introduction to Material  Balances"
     ]
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 6.1  Page no. 142\n"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "from numpy import matrix\n",
      "\n",
      "# Variables\n",
      "# Given\n",
      "P_O = 89 ;      # Premium octane -[octane/gal]\n",
      "S_O = 93 ;      # Supereme octane - [octane/gal]\n",
      "R_O = 87 ;      # Regular octane - [octane/gal]\n",
      "CP = 1.269 ;    # Cost of premium octane -[$/gal]\n",
      "SP = 1.349 ;    # Cost of supereme octane -[$/gal]\n",
      "RP = 1.149 ;    # Cost of regular octane -[$/gal]\n",
      "\n",
      "# Let x and y fraction of regular octane and supreme octane  is blended respectively,therefore: x + y = 1 ...(a)\n",
      "# and 89 = 87x + 93y ...(b)\n",
      "# Solve equations (a) and (b) simultaneously\n",
      "# Calculation\n",
      "a = matrix([[1,1],[87,93]]) ;          # Matrix of coefficients of unknown\n",
      "b = matrix([[1.0],[89.0]]) ;           # Matrix of constant\n",
      "a = a.I\n",
      "c = a * b\n",
      "cost =  c[0]*RP + c[1]*SP ;       # Cost after blending - [$/gal]\n",
      "sv = CP - cost ;                  # Save on blending - [$/gal]\n",
      "\n",
      "# Result\n",
      "# Check whether there is loss or save\n",
      "if (sv<0):\n",
      "    print 'We will not save money by blending.'\n",
      "else:\n",
      "    print 'We will save money by blending, and save is %.3f $/gal.'%sv"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "We will save money by blending, and save is 0.053 $/gal.\n"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      " Example 6.2 Page no. 147\n"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "\n",
      "# Variables\n",
      "fd= 1000.0 ;      #feed rate-[L/hr]\n",
      "cfd= 500.0;       #Weight of cells per litre- [mg/L]\n",
      "dn= 1.0 ;         #Density of feed-[g/cm**3]\n",
      "wp= 50.0 ;        # Weight percent of cells in product stream\n",
      "\n",
      "# Calculation and Result\n",
      "Pg=(fd*cfd*dn)/(1000*wp*.01) ;      # Mass balance for cells \n",
      "print ' Product flow(P) per hour is %.1f g'%Pg\n",
      "Dg= (fd*dn*1000) - Pg*(wp*.01) ;    # Mass balance for the fluid\n",
      "print '  Discharge flow per hour is %.3e g'%Dg"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " Product flow(P) per hour is 1000.0 g\n",
        "  Discharge flow per hour is 9.995e+05 g\n"
       ]
      }
     ],
     "prompt_number": 3
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 6.3  Page no. 154\n"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "dn =  0.80 ;                        #Density of motor oil-[g/cm**3]\n",
      "\n",
      "# Calculation and Result\n",
      "in_ms = (10000*(0.1337)*62.4*dn) ;  #  Initial mass of motor oil in the tank -[lb]\n",
      "print ' Initial mass of motor oil in the tank is %.1f lb'%in_ms\n",
      "\n",
      "m_fr = .0015 ;                      #Mass fractional loss\n",
      "print '  Mass fractional loss is %.4f '%m_fr\n",
      "\n",
      "Dsg = m_fr*in_ms ;                  # Mass balance for the fluid\n",
      "print '  Discharge of motor oil on flushing flow for 10000 gal motor oil is %.1f lb'%Dsg"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " Initial mass of motor oil in the tank is 66743.0 lb\n",
        "  Mass fractional loss is 0.0015 \n",
        "  Discharge of motor oil on flushing flow for 10000 gal motor oil is 100.1 lb\n"
       ]
      }
     ],
     "prompt_number": 4
    },
    {
     "cell_type": "code",
     "collapsed": true,
     "input": [],
     "language": "python",
     "metadata": {},
     "outputs": []
    }
   ],
   "metadata": {}
  }
 ]
}