Writing a flowsheeting system

Having been introduced to modular programming in the form of MATLAB functions, this exercise is meant to give you a chance to get comfortable with the use of subroutines for decomposing problems into logical pieces.

Consider the (very simple and somewhat silly) flowsheet shown in the figure. It consists of two splitters and a mixer along with 6 streams. The purpose of this exercise is to write a simple flowsheet function that determines what the contents of each stream are, given the feed stream and the split ratios of each of the two splitters.

Write two functions, one to model a splitter and one to model the mixer. These functions should be written so that they can be used to model the flowsheet shown in the figure.

In other words, write a function called Splitter which has two arguments and returns two results:

function [S1, S2] = Splitter( splitratio, Sinput )



where

Variable

Description

Sinput

The input feed stream for the splitter. This stream will simply be a list of molar flows.

splitratio

The amount of the input stream to send to the first output stream (the top one for each splitter in the diagram above). This amount is specified as a ratio, a value between 0 and 1.

S1

The first output stream of the splitter. This will consist of a list of molar flows.

S2

The other output stream.



Note that the component flows of S1 and S2 should of course add up to the component flows of Sinput!

Also write a function called Mixer which has the following declaration:

function Soutput = Mixer(input1, input2)

with a similar interface to the Splitter (but not exactly the same!).

Then write a main function which uses the functions defined above, in the appropriate order and the correct number of times, to determine the contents of each stream in the flowsheet.

An Algorithm

The algorithm for this problem is shown below:

  Algorithm Flowsheet
    Given: feed stream
           split1 - split ratio for first splitter
           split2 - split ratio for second splitter
    apply splitter to feed stream using split1 to generate S1 and S2
    apply splitter to S1 to generate P1 and S3
    apply mixer to S2 and S3 to get P2
    output all streams in tabular form
  end Algorithm

The problem

Use the program you've written to solve the flowsheet assuming that the first splitter has splits the stream exactly in half (a split ratio of 0.5) and that the second sends two thirds to the top stream. The program should be written so that these values are part of the input to the main function, as should be the description of the feed stream. Try this out with a feed of 5 components with flows [ 10 20 13 2 45 ].

The output should list the component flows of all the streams (feed, products, and internal streams), in a well organized and easy to understand tabular form. See the two hints below, these may help you manipulate your data into a tabular form.


HINTS
  1. Often data is best represented in columns, you can transpose a row vector to a column vector using the operator ' . e.g.
    >>  y = x'
    
       y =
          1
          3
          5
          7
     
  2. In MATLAB two vectors can easily be combined to give a matrix - this is the most basic way to produce a table. For example:
    >>  z = [y y]
    
       z =
          1   1
          3   3
          5   5
          7   7