1MCT Modelling Concepts and Tools 2CFD Excel and MATLAB Revision We assume that you are able to use Excel confidently. If this is not so, work through one of the many Excel tutorials, which you can...

can you help with question 3, how to use solver to find k1 and k2.


1MCT Modelling Concepts and Tools 2CFD Excel and MATLAB Revision We assume that you are able to use Excel confidently. If this is not so, work through one of the many Excel tutorials, which you can access through the web. You should also be proficient in MATLAB basics. If you are not, you should spend time in the clusters improving your MATLAB skills. 1. Before you do a lot of work, remember to change the working directory in MATLAB to your area on the server 2. Vectors and matrices in MATLAB 2.1. A matrix is an array of numbers (but not all arrays are matrices). A 2D matrix has rows and columns. A vector can be represented by a 1D matrix. Create row vectors a = [1 3 5 7 9] and b = [2 1.5 1 0.5 0] using the colon operator. 2.2. Create the matrix A = . 2.3 Array operations are performed element by element e.g. if A and B are matrices of the same size, A.*B multiplies each element of A by the corresponding element in B. On the other hand A*B performs the matrix multiplication of A and B. Similarly, B = A.^2 squares every element of A, whereas B = A^2 means B = A*A. Try >> A = magic(4) % to make a 4 by 4 matrix (magic square) and then construct another square matrix of integers of size 4x4. Try >> B = round(10*rand(4)) Now try A.*B, A*B and A^2, and try B*A to see if it differs from A*B. What is the value of a^2? How would you square every element in a? Find the dot product of a and b in two different ways, one involving transposing a or b. 3. The file spores.xlsx attached (and on Canvas) contains the data in Table 1. These spore numbers are taken from a sterilisation process in a fermenter. It is vital that fermenters are sterile before being inoculated with the microorganisms that are to be grown, and this is usually done by heating the culture medium (“broth”) to 121(C for about 15 min. Some bacteria spores are very resistant to even this sort of treatment, and experiments are needed to decide how long the sterilization ought to be. If it is excessively long, vital nutrients in the broth might be destroyed, ruining the fermentation. It is proposed that spores in the broth that have yet to be affected by the heat (“unaffected” spores) might on eventually become sensitive to heat, so that after further treatment they die. Time (s) Number of spores (mL-1) unaffected sensitised dead 0 100000 0 0 1 85916 13397 687 2 73816 23653 2531 3 63419 31328 5253 4 54488 36891 8621 5 46813 40738 12449 6 40220 43195 16585 7 34556 44539 20905 8 29689 44999 25312 9 25507 44764 29729 10 21915 43990 34095 15 10259 35837 53904 20 4803 26101 69096 30 1053 11879 87068 40 231 4908 94861 50 51 1938 98011 60 11 747 99242 ÷ ÷ ÷ ø ö ç ç ç è æ 0 1 1 1 2 0 2 0 1 Let the number of unaffected, sensitised and dead spores at time t s be Nu, Ns and Nd respectively. The reaction scheme is therefore: Nu ( Ns ( Nd In CH 1MCT Modelling Concepts and Tools we derived the equation that describes the number of dead spores, assuming consecutive first order reactions. This is: ( ) ( ) (1) ... 1 1 2 1 1 2 1 1 2 2 0 d t k t k e k k k e k k k N N - - - - - - - = where N0​ is the number of spores initially, and k1 and k2 are rate constants (s-1). Open the data file in Excel. Add-in Solver through File – Options. Then use it to find values for k​1 and k​​2. This can be done by · Putting some starting values for k​1 and k​​2​ in cells on the spreadsheet. Use the raw data to decide the likely order of magnitude of these constants. Note: k​1 ≠ k​​2​. · Making a column of data for predicted dead spore numbers, using a formula based on equation (1) and the values of t, k​1 and k​​2 · Using a further cell to calculate the sum of the squares of the differences of the predicted and actual data · Use Solver to minimize the sum of the squares of the differences of the predicted and actual data, by adjusting k​1 and k​​2. Finally, plot equation (1) in Excel using your fitted values of k​1 and k​​2, and see how well it fits the experimental data. 4. You can move data from Excel files into MATLAB, using the Import Wizard. Start MATLAB and press the Import Wizard button: Import the Excel file into MATLAB. Note how you can select just the data and leave behind the header. The imported data appears in the MATLAB Array Editor, which you can also open for any variable in the Workspace by double clicking on it. Save your newly loaded Excel data as a mat file. 5. Script m-files Many MATLAB operations and functions can be used at the command line (in the Command Window). For simple problems, the command line is fast and efficient. For larger problems, or if you wish to change variable values, or have loops or branches, or may want to modify the commands, use script files. Commands can be stored in text or "script" files to be executed later from the command line. Such a file has an extension .m and is therefore called an m-file. MATLAB has a built-in editor. Running a “script” m-file is equivalent executing a sequence of commands at the command line. Start up the Editor and write a script file to calculate the surface area and volume of a sphere, an ellipsoid, a cube, a cylinder and a right cylindrical cone, asking the user for their choice of shape and its key dimensions. Note: n = input('Enter values for n in brackets: '); displays the message in quotes on the screen and accepts a value for n. Besides input, other useful functions to use in script files are given in the table below. disp(ans) Displays results without identifying variable names echo Turning echo on displays the script commands as they are executed - good for “debugging” input Prompts user for input pause Pause until user presses any keyboard key pause(n) Pause for n seconds waitforbuttonpress Pause until user presses mouse button or keyboard key menu Offers user options Try out some of these! 6. Plotting a single 2D curve in MATLAB: If xdata and ydata contain corresponding pairs of data values, plot(xdata, ydata) will plot the y values against the x values. Try plotting some of the Spores.xls data, including equation (1) using the values of k1 and k2 that you have already determined. If necessary, load the mat file of data you saved in Task 4. Check out the options in Help. This has changed significantly in the new interface so make sure you know how to use it. You should try to specify different styles and colours of lines and markers. Messing on is recommended! By default, plot deletes existing lines and resets all axes when a new plot command is made. To add lines to an existing plot, use hold on. The axes may still be rescaled; to stop this, the command is axis manual before the second plot. You can annotate graphs with title, xlabel, ylabel, text, plotedit. There is access to plot editing tools from a button in the Figure Window. Try this for yourself; it is powerful (and fun). 7. Function m-files A more advanced use of m-files is to write your own functions. A function accepts an input (or inputs) and gives an output (or outputs) having done something (often a calculation) in between. Think of >> y = sin(x) sin is a function, x is the input "argument" and y is the output "argument". There are many functions available in MATLAB. sin is a built-in function, and you can't see the code. (It is probably the sum of a series.) Other functions can be opened in the Editor so you can see the code, and change it if you want. As an example, look at humps, which takes in values of x, and outputs values of y. >> y = humps(x) You could look at how this function m-file is constructed by entering >> type humps at the command line. 9. Function application Equation (2) is the Colebrook equation, which gives the friction factor f for turbulent flow of an incompressible fluid in a cylindrical pipe : (2) ... 51 2 7 3 86 0 1 ÷ ÷ ø ö ç ç è æ + e - = f Re . D . ln . f where ( is the roughness of the pipe, D is its internal diameter and Re is the Reynolds number. If D e = 1.2 ( 10-4 and Re = 2 ( 105, use MATLAB to find f. First write your own Colebrook function m-file, so that (3) ... 51 2 7 3 86 0 1 ) Colebrook( ÷ ÷ ø ö ç ç è æ + e + = f Re . D . ln . f f You will have to declare e = D e and Re as global variables both inside Colebrook and in the calling program. This allows these parameter values to be passed into Colebrook for use in the calculations. Then use fzero('Colebrook', 0.02) or fzero(@Colebrook, 0.02) to find the value of f that makes Colebrook zero. The second argument in the definition of fzero is an initial guess; f ( 0.02. Check the Help files for more on function functions, fzero, and function handles “@”. Note: The use of global parameters is no longer considered good programming practice. MathWorks recommend passing such parameters into functions as input arguments. However, fzero will not accept multi-argument functions and to do this you must use nested functions. See the Help files if you want to learn how to do this. Table 1: Spore sterilisation data Adapted from T.K. Ghose (1990), Bioprocess Computations in Biotechnology, Volume 1 � A. Constantinides and
Sep 30, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here