Download presentation
Presentation is loading. Please wait.
Published byMaud Wood Modified over 9 years ago
1
1 Tips for solving Project 1 Reactor SO 3 SO 2 +O 2
2
2 Reactor In Project 1 you are asked to develop differential equations to solve for the total pressure, temperature, gas velocity and partial pressures at steady state on a reactor. Then you need to solve a set of differential equations. How can that be done in Matlab? v (z)=? P (z)=? T (z)=? P i (z)=? z
3
3 Let’s take a look at the following very simple, worked-out example:
4
4 Notice that we have a system of 2 ordinary differential equations with its boundary conditions. The solution is How’s the script in Matlab?
5
5 We start a script on the Matlab Editor and give a name to it We should save the file with the same name, for example: “project_1_example.m” If we want to have the results for “f” and “g” available on the workspace, we need to give them as the output on the same line
6
6 Next, to avoid problems and a lot of confusion, a good habit when programming in Matlab, is to clear the memory for all variables from previous simulations before we start a new one. So on the top of the program we can use the command “clear all” Also we can use “clc” to clear the Command Window; and “close all” to close any graphics we might have open
7
7 Then we define the parameters that are going to be globally available by declaring them global
8
8 Then, we set the values of those parameters A semicolon at the end of the line avoids displaying this line on the screen when the script is run
9
9 Next, we specify the integration interval over which Matlab should integrate. For that, we create a vector containing the initial and final values for the independent variable
10
10 We can always make comments about our code. This helps remember what we were doing when we see the code in the future. Matlab ignores all the text after a percentage sign (%). Next, we specify the integration interval over which Matlab should integrate. For that, we create a vector containing the initial and final values for the independent variable
11
11 Now we set the boundary conditions on a vector “x0”. First we give the value for “f” and then the one for “g” If we had, let’s say, 3 differential equations, we would simply give here a vector with 3 columns. We would proceed in a similar fashion if we had only one equation instead of a system
12
12 Here we use the function “odeset” which will allow us to specify options to the ODE solver. For instance “abstol” determines the maximum error for every component of the solution
13
13 Other options are available, for example to control the step size and so on.
14
14 Here we call the ODE solver “ode15s”
15
15 Here, “x” is a vector with the discretization in the independent variable. The number of points will be determined by Matlab, automatically. The number of points will increase as we demand smaller tolerances through the “odeset” function.
16
16 “y” is a solution array that contains the solutions, as columns. Each row in the solution array “y” corresponds to a value in the column vector “x”
17
17 Here we give the name of the.m file where we have written the equations. (We will see the script in a few slides!)
18
18 “xspan” is the vector with the integration interval that we defined previously
19
19 “x0” is how we called the initial values vector of our differential equations
20
20 “project_1_options” are the options that we defined regarding error tolerances
21
21 We have provided the ODE solver with all the information that it needs to deliver the solution to us! Next on the script we shall plot the results obtained
22
22 We have used here “ode15s”, but other solvers are available. Which one is best will depend upon the properties of the system that we are solving, for example, its stiffness
23
23 Next we define the vectors “f” and “g” equal to the first and second columns of the solution array “y”
24
24 Finally, we plot the functions “f” and “g” on the same figure using the function “subplot”
25
25 Now let’s take a look at the script “math_example.m” where we write the equations
26
26 Now let’s take a look at the script “math_example.m” where we write the equations “dydx” is the output (the solution array) that contains the columns with the values for “f” and “g”
27
27 Now let’s take a look at the script “math_example.m” where we write the equations “dydx” is the output (the solution array) that contains the columns with the values for “f” and “g” “x” is the independent variable and “y” is array that contains both “f” and “g”
28
28 Here we make visible the global parameters to the function “math_example”
29
29 Next, we identify our functions in the “y” array
30
30 Here we write the system of equations
31
31 And now we put the derivatives togheter in the array “dydx” It’s done!
32
32
33
33 The results with A=1 and B=2
34
34 Some more tips… In the problem you are asked to find the total pressure. Using the balance for component j we find that for steady-state and without dispersion, we have: Using the ideal gas law to replace c j :
35
35 Some more tips… Now we need to operate to get an expression for the derivative of p j with respect to z… Then solving for the derivative of pressure, we obtain
36
36 Some more tips… In the problem you are also asked to find the gas velocity. For plug-flow the total molar flux is: Using again the ideal gas law, where the total pressure is P, and differentiating:
37
37 Some more tips… Solving for the derivative of velocity, we obtain: So we have found what Matlab needs as input: an expression for the derivative of velocity. For the total pressure, we have from plug-flow theory:
38
38 Some more tips… But since the mass flux is constant, we know that So the Ergun equation can be written as
39
39 Some more tips… Now let’s look at the temperature. The energy equation is: Now taking we get:
40
40 Some more tips… Solving for the derivative of temperature, we obtain where and
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.