IT1005 Introduction to Programming with MATLAB Lab 7 – Nonlinear equations The objective of this lab is to step you through important concepts in solving nonlinear equations using MATLAB. We will do this by focusing on two specific applications in different fields on study – urban planning and chemical engineering. The first problem will require you to tackle a problem of estimating populations for urban planning. This problem will get you going on the basics of root finding. In the second problem, we will try to generate pressure-volume phase diagrams by solving the R-K equation of state over a range of pressures and temperatures. The main objective here is to get you to use your programming skills in conjunction with in-built MATLAB functions such as fsolve. This lab is worth a total of 25 marks, Pr.1 = 10, Pr. 2 = 15 Released: Thursday, October 10, 2013 Deadline: Friday, October 18, 2013 Your solutions to this lab must be compiled into a word document, and submitted to IVLE on or before the deadline, as usual. NOTE: Those in Tuesday lab groups (4A, 5A+5B, 6A+6B, 3A+3B) will be affected by the Hari Raya Haji public holiday on Tuesday 15 Oct 2013. Affected students (6*18+28 ~ 140 students) have three options: a. Attend any Monday (14 Oct) or Wednesday (16 Oct) lab groups. b. Attend extra class (in case you cannot attend any of the Monday/Wednesday groups): Wednesday 16 Oct 2013, 12-2pm @ I3-3-46 (with Liu Xinyan) or I3-3-47 (with Ong Chee Chin). c. Do Lab 7 on your own. We will not record attendance on Week 09. Problem 1 Urban planning and population estimates Accurate population estimates form the underlying quantitative basis for urban planning and development efforts for any city such as Singapore. For example, transportation and traffic engineers might find it necessary to determine separately the population growth trends of the central areas with significant commercial activity and those of nearby suburban areas (eg. Tanjong Pagar GRC versus Tampines GRC). Let us consider one such case. The population of a certain urban area (Pu) is declining with time according to the following empirical formula obtained from census estimates: Pu (t) = Pu,max e −ku t + Pu,min In contrast, the population of a connected suburban area (Ps) is growing according to the following quantitative estimate: € Ps (t) = Ps,max ⎡ Ps,max ⎤ −k t 1+ ⎢ −1⎥e s ⎣ P0 ⎦ In the above formulas, Pu,max, Pu,min, ku, Ps,max, P0 and ks are empirically derived parameters from census data and urban planning targets set by the city. The parameter € values are as follows: Pu,max = 75,000, Pu,min = 100,000, ku = 0.045/yr, Ps,max = 300,000, P0 = 10,000 and ks = 0.08/yr. (a) In this problem, you are required to determine the time (in years) and corresponding values of the two populations when the suburban area is 20% larger than the urban area. You will first need to take the given two formulas, and formulate a single new equation of the type f (x) = 0 in accordance with the objective given above. How do you do it? What is ‘x’ here? An appropriate solver to use would be ‘fsolve’. Experiment with several initial guesses. What do you find? Briefly discuss your findings (2-3 sentences) (b) You can also verify your answer graphically. How? Try doing this using one MATLAB plot. Problem 2 Phase diagrams and equations of state We have briefly discussed in class how ‘equations of state’ can be used to describe the pressure-volume-temperature behavior of a gas (you will see much more of this in year 2 thermodynamics). The Redlich-Kwong (R-K) equation of state, is a more sophisticated description of such behavior than the ideal-gas law (Pv = RT). The R-K equation of state is given by: where R = universal gas constant [=0.518 kJ/(kg K)], T = absolute temperature (K), P = absolute pressure, measured in kilo Pascals (kPa), and v = the volume of a kg of gas (m3/kg). The parameters a and b for methane (CH4) are calculated as follows: where PC = ‘critical’ pressure of the gas = 4580 kPa, and TC = ‘critical’ temperature of the gas = 191 K (More about this in CN1111!). (Warm-up exercise) We can use the idea of ‘anonymous functions’ to solve the above equation for v, given the values of T and P. Please refer to the posted supplementary notes on anonymous functions, and make sure you understand this nice ‘trick’. Now, in this problem, you are required to generate a ‘phase diagram’ for methane. In other words, you are required to generate a GRAPH of volume (v) versus pressure (P), at a fixed temperature T. (a) Use MATLAB to generate a graph of volume versus pressure. The graph is required at T=400 K, and for pressures between 10,000 kPa and 250,000 kPa. Let there be a spacing of 10,000 kPa between pressures on the graph. [HINT] (i) You will have to use ‘fsolve’ inside a loop, and (ii) a useful initial guess for all cases is v = 0.01 (I estimated this using the ideal gas law…). (b) Repeat (a), but this time, plot two additional curves on the same graph, corresponding to T = 600 K, and T = 800 K, for the same pressure range. Preferably plot the three curves in different colors, so you know which one corresponds to what temperature. [HINT] (i) An additional loop is required, and (ii) use initial guesses as above.