<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Paritosh Usmanpurkar on Medium]]></title>
        <description><![CDATA[Stories by Paritosh Usmanpurkar on Medium]]></description>
        <link>https://medium.com/@usparitosh?source=rss-d75a97ace8bf------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*CDCGjBjgB7Os2FpHn4GS1g.jpeg</url>
            <title>Stories by Paritosh Usmanpurkar on Medium</title>
            <link>https://medium.com/@usparitosh?source=rss-d75a97ace8bf------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 21:33:28 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@usparitosh/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[The dimension of the Residence Time Distribution function is 1/Time.]]></title>
            <link>https://medium.com/@usparitosh/the-dimension-of-the-residence-time-distribution-function-is-1-time-5b1fbe2972ef?source=rss-d75a97ace8bf------2</link>
            <guid isPermaLink="false">https://medium.com/p/5b1fbe2972ef</guid>
            <category><![CDATA[reactor-design]]></category>
            <category><![CDATA[rtd]]></category>
            <category><![CDATA[chemical-engineering]]></category>
            <dc:creator><![CDATA[Paritosh Usmanpurkar]]></dc:creator>
            <pubDate>Wed, 03 Jun 2020 07:30:25 GMT</pubDate>
            <atom:updated>2020-06-03T07:30:25.085Z</atom:updated>
            <content:encoded><![CDATA[<h3>The dimension of the RTD function is 1/Time.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5HanGb71fkSKM4iuca0hWQ.jpeg" /></figure><p>I’ll introduce the topic later on. Before that, I want to emphasize the fact of how we are familiar with the physical interpretation of <strong>E(t)dt</strong>. Yes, it is the fraction of particles that have a residence time between t and t+dt or, the fraction of particles that escaped the control volume between time t and t+dt after they were injected.</p><p><strong>But</strong>, can you think of what is the physical interpretation of E(t)? Not E(t)dt, just E(t). It is known as the RTD function. But what does it signify?</p><p>Upon pondering a bit, you will realize the units of E are 1/time (It isn’t dimensionless, as your intuition might incorrectly guess at first).</p><p>Here goes the introduction: There are two types of ideal reactors, Continuously Stirred Tank Reactor and the Plug Flow Reactor. The former is used when you want to keep the concentration of the reactant very low. The latter is used when you want to keep the concentration of the reactant the highest (This choice depends on selectivity/yield considerations).</p><p>The assumptions of the CSTR are: Perfectly mixed, and the exit concentration is the same as the concentration in the tank. Similarly, for the PFR, the assumption is Plug flow(No axial mixing). But in reality, due to many non-idealities, the reactor behavior can deviate highly from these two ideals. We need a way to quantify this deviation. One of the methods is to study the RTD of our real reactor.</p><p>Consider any reactor. We want to get the RTD of this reactor. For this, we will first let a steady stream of any liquid flow through the reactor. Then, inject a certain amount of a tracer in the entering fluid stream and measure the concentration of this tracer in the exit stream with time. Let this concentration be denoted by C(t). the volumetric flow rate of liquid is <em>ν.</em></p><p>Now, the amount of tracer exiting the reactor between time t and t+Δt<em> </em>will be</p><p><em>ΔN = C(t)νΔt</em></p><p>Let us divide both sides of the above equation by Nₒ (Total amount of tracer injected).</p><p><em>ΔN/</em>Nₒ<em> = </em><strong><em>(</em></strong><em>(C(t)ν)/</em>Nₒ<strong>)</strong><em>Δt</em></p><p>The term inside bold brackets on the right-hand side of the above equation is the RTD function E(t).</p><p><em>ΔN/</em>Nₒ<em> = E(t)Δt</em></p><p>As mentioned above, we can see E(t)<em>Δt </em>is the fraction of tracer exiting between time t and t+Δt<em>.</em></p><p>To find the physical interpretation of E(t), lets first rearrange the very first equation.</p><p><em>ΔN/Δt = C(t)ν</em></p><p>The units of quantities on both sides are moles/s. The LHS can be thought of as “Time rate of change of the amount of tracer exiting the reactor”.</p><p>Divide both sides by Nₒ.</p><p><em>Δ(N/N</em>ₒ)<em>/Δt = E(t)</em></p><h4><strong>Thus, we can interpret E(t) as the rate of change of the fraction of the tracer exiting the reactor.</strong></h4><p>For example, let us try to apply this thought to the RTD of ideal PFR. The RTD of PFR is given by <strong>δ(t-τ)</strong>. Where <strong>δ </strong>is the Dirac delta function and <strong>τ </strong>is the spacetime of the reactor. The value of the RTD function is infinite at <strong>t = τ </strong>and zero everywhere else. According to our conclusion, the RTD is the rate of change wrt time of fraction of particles exiting the reactor. Suppose we track the cumulative fraction as a function of time. we start at <strong>t=0</strong>. The fraction will stay 0 till <strong>t = τ </strong>where it abruptly becomes 1. Now, E(t) at <strong>t = τ </strong>will be</p><h4>(1–0)/0 = <strong>∞</strong></h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5b1fbe2972ef" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Tuning a PI controller for a water heating system]]></title>
            <link>https://medium.com/@usparitosh/tuning-a-pi-controller-for-a-water-heating-system-69426277c77a?source=rss-d75a97ace8bf------2</link>
            <guid isPermaLink="false">https://medium.com/p/69426277c77a</guid>
            <category><![CDATA[matlab]]></category>
            <category><![CDATA[chemical-engineering]]></category>
            <category><![CDATA[simulink]]></category>
            <category><![CDATA[process-control]]></category>
            <dc:creator><![CDATA[Paritosh Usmanpurkar]]></dc:creator>
            <pubDate>Sun, 12 Apr 2020 17:18:37 GMT</pubDate>
            <atom:updated>2020-04-12T17:18:37.673Z</atom:updated>
            <content:encoded><![CDATA[<p>In this article, we will first derive a mathematical model for a water heating system from first principles and then tune a PI controller(Just PI and not PID because our system is first-order) by the direct synthesis method and though the MATLAB PID tuner and compare the two results.</p><p>The system is pretty simple. Water continuously enters the electrical heater and leaves at the same flow rate. hence the volume is constant throughout. The only disturbance variable here is the inlet flow rate. The manipulated variable will be the heater power input. we need to tune a PI controller to manipulate the heater power in order to keep the outlet temperature near a set point temperature. Hence the control variable is the outlet temperature.</p><p><strong>Deriving the model</strong>:</p><p>We will be assuming that the heating element of the electrical heater has negligible capacitance. This means that the electrical energy will be transferred to the water extremely fast.</p><p>Mass and Energy balance:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RBUkXuvF2sS_S_rYioEzGQ.png" /></figure><p>where w is the mass flow rate, T is temperature and Cp is the heat capacity of water, rho is density and V is the volume of the heater.</p><p>After linearizing the above energy balance equation and representing it in terms of deviation variables we get:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3_90P8mjiJdr5Qyg88a6rw.png" /></figure><p>Now we take Laplace Transform on both sides of the above equation and obtain the two transfer functions:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*af1brsAmB1y-ithzsCckRQ.png" /></figure><p>I have taken into consideration the actual set up present in the Process Control Lab in BITS Goa. The volume of the heater is 0.5 lt. We can take the inlet temperature as 25 degrees and the setpoint temperature as 30 degrees celsius.</p><p>Substituting these values in the above two transfer functions we get:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eaWCCtty2RHrNn8MpwXezA.png" /></figure><p>We will also include an arbitrary time delay of 1s. hence, the final Transfer functions will be the ones shown above multiplied by Exp(-s).</p><p><strong>Tuning the PID Controller:</strong></p><p>For finding the controller settings, I have referred to “Dale E. Seborg, Thomas F. Edgar, Duncan A. Mellichamp — Process Dynamics and Control-Wiley (2003)”.</p><p>We will use the “Direct synthesis method”. Since we have a first-order process, the resulting controller obtained from this method is a PI controller. To get a PID controller, the order of the process has to be 2 at the least. We can make our system a second-order one by removing a few of the assumptions but then we would need information like the mass of the heating element and the heat transfer coefficient, which we don’t have. Hence, we would keep the system first order.</p><p>Next, we arbitrarily choose the closed loop system time constant as 1 s for now.</p><p>Then we find the controller settings by the Direct Synthesis method and by PID tuner, which turn out to be:</p><p>DS: Kc = 1.05, τi = τ = 45 (or in other words, Kp = 1.05 and Ki = 1.05/45 = 0.023).</p><p>PID Tuner: Kp = 1.182, Ki = 0.01164.</p><p>We can see that these values are pretty close enough. Now, we will simulate a control loop with these settings in Simulink.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4hZHe9J6kowqD9KVJt1MLQ.png" /></figure><p>The step change in setpoint happens at t = 0s and step change in disturbance (Increase in flow rate by 10 LPH or 0.00277 kg/s) change at t = 50s.</p><p>The responses for the two settings are shown below.</p><p>DS method:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IEpfLh8cDUguhflAzgxrCw.png" /></figure><p>PID tuner:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*puID-vIsW9HFlBcU19wFOA.png" /></figure><p>As you can see, the responses are pretty sluggish (Settling time is around 10s) and overshoot is about 6%. we can tweak these settings to obtain a better performing controller.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=69426277c77a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How valves control flow-rate and how they are similar to orifice plates.]]></title>
            <link>https://medium.com/@usparitosh/how-valves-control-flow-rate-and-how-they-are-similar-to-orifice-plates-fbef5aae8758?source=rss-d75a97ace8bf------2</link>
            <guid isPermaLink="false">https://medium.com/p/fbef5aae8758</guid>
            <category><![CDATA[fluid-mechanics]]></category>
            <category><![CDATA[cfd]]></category>
            <category><![CDATA[chemical-engineering]]></category>
            <dc:creator><![CDATA[Paritosh Usmanpurkar]]></dc:creator>
            <pubDate>Sat, 28 Mar 2020 06:26:19 GMT</pubDate>
            <atom:updated>2021-02-26T05:21:22.134Z</atom:updated>
            <content:encoded><![CDATA[<p>If you have ever wondered how valves control the mass flow-rate, you aren’t alone. Apply the continuity equation on a valve. The final velocity should be greater than the initial velocity. Even though the cross-sectional area decreased, the velocity has increased. Hence the mass flow-rate should stay the same right? NO! Here’s why:</p><p>We will proceed with the explanation after going through some experimental data first. I was able to get my hands over a Linear Valve (Discharge flowrate is a linear function of the valve lift) fitted with a valve positioner. We won’t go into the details of the mechanical working of the control valve here.</p><p>The upstream pressure and Discharge flowrate were recorded for different valve openings. Here’s the data:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*488-MMe_Tg0X-TW5VGMxoA.jpeg" /></figure><p>And this is how the apparatus looks like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/661/1*0bKgenzC_mhuoDsX4g0UjA.png" /></figure><p>The data is tiny as the valve stem kept fluctuating. Anyways, this data is sufficient for making the required conclusions. First of all, the discharge flow rate is directly proportional to the valve lift. This is very obvious as the valve is a linear valve. Next, the upstream pressure increases significantly as the valve opening is decreased. This means the upstream velocity head is converted to pressure head. Since velocity has reduced, the <strong>flow rate has reduced. This shows that the valve is altering the upstream pressure and thus controlling the pressure</strong>.</p><p>Now, another doubt might arise at this point. <strong>How different is a control valve from an orifice plate? </strong>Because both of them are creating constrictions in the flow. Hence even an orifice plate should reduce the flow rate by some amount. We will answer this question by simulating this system in COMSOL 5.2.</p><p>Here I have used the 2-D axisymmetric space dimension and stationary study.<strong> We consider 2 systems:</strong> In the <strong>first</strong>, we have a 1m long pipe with 10 cm inner diameter. The <strong>second</strong> system consists of the same pipe but with an orifice plate at 40cm from the inlet. The orifice plate is 2cm thick and has an inner diameter of 4cm. In both cases, the water enters at 2m/s, and the outlet pressure is 101325 Pa.</p><p>Results:</p><p>Pipe:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/938/1*dYZczTW_TdNltmQ4s7iG7Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/938/1*l5A-gKvqVUsS09RsjIYhxw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/938/1*7SIy3PwfjSeCkH_32_S2uQ.png" /><figcaption>Geometry, Pressure profile and the Velocity profile for the pipe system.</figcaption></figure><p>Orifice:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/938/1*0BC3YqKU8s9vqMZDy7Kv7Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/938/1*aye7s9ZNyBEbqzmWZFq3QA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/938/1*tHkB8JkRydsnl0UQ13-Mrg.png" /><figcaption>Geometry, Pressure profile and the Velocity profile for the orifice plate in the pipe system.</figcaption></figure><p>The velocity profiles obtained are pretty obvious. We can easily see that the pressure in the pipe system decreases gradually. But, in the orifice plate system, the pressure is significantly raised upstream to the orifice plate. Remember that these results correspond to similar boundary conditions: Inlet velocity = 2 m/s and outlet pressure = 101325 Pa.</p><p>Hence, if we want the same pressure drop in both the systems, the inlet velocity in the orifice plate system will have to be lower than that in the only pipe system. Lower velocity means a lower flow rate. <strong>Hence Proved!!</strong> The orifice plate acts as a control valve. In fact, control valves are sometimes called variable orifices.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fbef5aae8758" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why we use Log mean temperature difference and not average temperature difference in heat…]]></title>
            <link>https://medium.com/@usparitosh/why-we-use-log-mean-temperature-difference-and-not-average-temperature-difference-in-heat-26186cbc0987?source=rss-d75a97ace8bf------2</link>
            <guid isPermaLink="false">https://medium.com/p/26186cbc0987</guid>
            <category><![CDATA[heat-exchanger]]></category>
            <category><![CDATA[heat-transfer]]></category>
            <category><![CDATA[chemical-engineering]]></category>
            <dc:creator><![CDATA[Paritosh Usmanpurkar]]></dc:creator>
            <pubDate>Wed, 25 Mar 2020 16:02:56 GMT</pubDate>
            <atom:updated>2020-08-26T09:18:42.676Z</atom:updated>
            <content:encoded><![CDATA[<h3>Why we use Log mean temperature difference and not average temperature difference in heat exchangers?</h3><p>I have been asked this question almost 3–4 times by the lab teaching assistants in several lab sessions.</p><p>What they expect you to say is, the temperature difference between the hot and the cold side throughout the heat exchanger keeps changing, and it is best characterized by log. This argument is correct but isn’t the answer to the question. <strong>The truth is</strong>, after a simple analysis, we arrive very conveniently, at a relationship that shows us that the relationship is logarithmic. Mind you that, this is true irrespective of the flow being co-current or counter-current.</p><p>Here is the analysis:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/511/1*7Jw-WrYF7Al-mJWaz27Rzg.png" /></figure><p>For any element of area dA, the heat transferred will be:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/313/1*NE8sxuQblg-sy4FIlg9oXA.png" /><figcaption>Equation 1</figcaption></figure><p>Solving for differential temperature changes, we get:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/200/1*zpDox_fXWqI_efFnEMEqlQ.png" /><figcaption>Equations 2 and 3</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/524/1*FVmrsCf-u1vGxDpwghzwjQ.png" /><figcaption>Equation 4</figcaption></figure><p>Where the subscripts h and c stand for hot and cold respectively. The heat transfer can also be written as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/226/1*6BP15d7GlyNI8rgtckqtfw.png" /><figcaption>Equation 5</figcaption></figure><p>Now, substitute Equation 5 in Equation 4.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/434/1*w03Z11-ZeexlHusVq6Ytyw.png" /><figcaption>Equation 6</figcaption></figure><p>Now integrate Equation 6 from point 1 to 2.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/434/1*0Bu04vmVLVD-bXS-m6MK8Q.png" /><figcaption>Equation 7</figcaption></figure><p>Now back substitute values of mc in terms of total heat transfer in Equation 7.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/235/1*qLbCyRXLm3RRRpawTGZrqQ.png" /><figcaption>Equation 8</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/405/1*EoOtAqPK_10-jOz2xVgDcg.png" /><figcaption>Equation 9</figcaption></figure><p>The third term on the right hand side of Equation 9 is the Log Mean Temperature Difference.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=26186cbc0987" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[MATLAB App tutorial: Making an app for finding the ideal number of Gas Absorber stages graphically.]]></title>
            <link>https://medium.com/@usparitosh/matlab-app-tutorial-making-an-app-for-finding-the-ideal-number-of-gas-absorber-stages-graphically-7f3e78995652?source=rss-d75a97ace8bf------2</link>
            <guid isPermaLink="false">https://medium.com/p/7f3e78995652</guid>
            <category><![CDATA[matlab-app]]></category>
            <category><![CDATA[mass-transfer]]></category>
            <category><![CDATA[gas-absorption]]></category>
            <category><![CDATA[chemical-engineering]]></category>
            <dc:creator><![CDATA[Paritosh Usmanpurkar]]></dc:creator>
            <pubDate>Sun, 22 Mar 2020 17:24:08 GMT</pubDate>
            <atom:updated>2020-03-22T17:34:58.874Z</atom:updated>
            <content:encoded><![CDATA[<p>This tutorial explains how to make an app using MATLAB App Designer, which finds the number of theoretical stages of a countercurrent Gas Absorber required for achieving the given separation. The inputs to the app will be the solute concentration in the inlet gas stream, outlet gas stream, solvent stream, and the inlet liquid and gas flow rates.</p><p>You can download the .mlapp file from:</p><p><a href="https://in.mathworks.com/matlabcentral/fileexchange/74675-gas-absorption-operation">https://in.mathworks.com/matlabcentral/fileexchange/74675-gas-absorption-operation</a></p><p>Before going to the tutorial, we would first touch upon briefly what Gas Absorption is.</p><p>Gas Absorption<strong> </strong>is a Unit Operation of Chemical Engineering in which some components in a gas stream are selectively transferred to a liquid stream by bringing these two streams in close contact. The contact is facilitated by different types of packings.</p><p>The gas stream which has to be treated enters the bottom of the column. The solvent stream enters from the top. The solvent liquid spreads evenly on the packing. Interphase Mass Transfer occurs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/216/1*vwcymNIhVNr3k25ZlUwmsA.png" /></figure><p>After making a mass balance between any stage n and the bottom-most stage, we get the equation of the operating line:</p><p>Gₛ(Y₁-Y) = Lₛ(X1-X)</p><p>Where Gₛ and Lₛ are the solvent frow rates.</p><p>Gₛ = G/(1+Y) &amp; Lₛ = L/(1+X)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/563/1*1sBDqNl7-sfvueA5NZ9V3A.png" /></figure><p>The equation of the Equilibrium curve can be either represented by Henry’s law or can be found out from experimental data.</p><p><strong>Building the app:</strong></p><p>We will be using the MATLAB App designer for making this app. The first step is to drag and drop all the required components. We will have 2 tabs, one for inputs and the other for results. I have also pasted an image depicting the variables of the column. we will be including 2 ways of inputting the equilibrium data -</p><ul><li>manually entering X, Y points</li><li>providing the value of m (y = m*x)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/966/1*aGSmX9GvwSRm7rOWNPD9Lg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/854/1*_mhCBpqUZIcLnnFnwSsYNg.png" /></figure><p>Now we move on to the code. Making an app on MATLAB App designer is very easy as it writes a part of the code itself. We just have to write the code for the main functions of the app.</p><p>First, we will include a property called ‘Data’ to store the values entered in the table. <strong>properties can be added from the ‘Insert’ section in the ‘Editor’ tab.</strong></p><pre>properties (Access = private)<br>    Data<br>end</pre><p>Next, we will define a startup function. Here, we will give the initial dummy values to the table and the rest of the input variables. This dummy data is useful when you just have to test the app. The code indentation is disturbed here. Make sure to correct it.</p><pre>x_c1=[0;0.05;0.1;0.15;0.2;0.25;0.3;0.35;0.4;0.45;0.5;0.55;0.6;0.65;0.7;0.75;0.8;0.85;0.9;0.95;1];<br>y_c1=[0;0.004784689;0.009174312;0.013215859;0.016949153;0.020408163;0.023622047;0.02661597;0.029411765;0.03202847;0.034482759;0.036789298;0.038961039;0.041009464;0.042944785;0.044776119;0.046511628;0.04815864;0.049723757;0.051212938;0.052631579];<br>          <br>app.Data = table(x_c1,y_c1);<br>app.UITable.Data =table2cell(app.Data);<br>app.UITable.ColumnEditable=[true true];<br>app.mEditField.Value = 0.01;<br>app.X2EditField.Value = 0.2;<br>app.Y2EditField.Value = 0.004;<br>app.Y1EditField.Value = 0.01;<br>app.L2EditField.Value = 1;<br>app.G1EditField.Value = 100;</pre><p>Now we have all our required inputs. At this stage, if you run the app, you will be able to see the above values already present in the input boxes. If you press the ‘Run’ button, nothing will happen because we haven&#39;t defined any ‘Button pushed function’. To add a button pushed function, you can right-click on the run button in the design view, then ‘callbacks’ → ‘Add ButtonPushedFcn callback’. we will write all the things we want our app to do in this function.</p><p>Let’s first list the things we want to do:</p><ul><li>Take inputs from the edit fields and store them in variables.</li><li>Then, depending on which method of equilibrium data entry is selected, create arrays X and Y which store this equilibrium data.</li><li>Generate a ‘griddedInterpolant’ for this equilibrium data. This will be used when we want to find the equilibrium Y for a given X.</li><li>Generate the equation of the operating line.</li><li>Then check whether the exit gas concentration is greater than the equilibrium gas concentration and whether the liquid rate is greater than the minimum liquid rate. The first one of these is pretty easy to check. For the second one, we will find the zeros of the equation: Operating line-Equilibrium curve. If the solution is Nan or doesn&#39;t lie between X2 and X1, the number of stages can be calculated.</li><li>Then we find the number of stages and plot the operating line, the equilibrium curve and the stages.</li><li><strong>To keep the program simple, we are not going to find the minimum liquid rate. The user has to find a suitable liquid rate by trial and error.</strong></li></ul><p>This is what we write inside the Run button pushed function:</p><pre>%Clearing the plot.<br>cla(app.UIAxes)</pre><pre>%Take the values of all inputs in variables first<br>Y1 = app.Y1EditField.Value;<br>Y2 = app.Y2EditField.Value;<br>G1 = app.G1EditField.Value;<br>X2 = app.X2EditField.Value;<br>L2 = app.L2EditField.Value;</pre><pre>Ls = L2/(1+X2);<br>Gs = G1/(1+Y1);<br>slopeopl = Ls/Gs;<br>X1 = X2 + (Y1-Y2)/slopeopl;</pre><pre>%Storing Equilibrium data in X and Y arrays<br>switch app.DataentrymethodSwitch.Value<br>    case &#39;m&#39;<br>        m = app.mEditField.Value;<br>        X = linspace(X2,X1);<br>        Y = m.*X./(1+X.*(1-m));<br>      <br>        <br>    case &#39;Enter values manually&#39;<br>       app.Data=cell2table(app.UITable.Data);<br>       X=table2array(app.Data(:,1));<br>       Y=table2array(app.Data(:,2));<br>end</pre><pre>%y=fcn(x)<br>h = griddedInterpolant(X, Y, &#39;pchip&#39;);<br>%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%</pre><pre>%Checking is Y2 is above the equillibrium curve<br>stopsignal = 0;<br>Y2_equilibrium = h(X2);<br>if Y2 &lt; Y2_equilibrium<br>    errormsg = &#39;error: Exit gas concentration lesser than Equilibrium Concentration.&#39;;<br>    app.RunstatusEditField.Value = errormsg;<br>    stopsignal = 1;<br>end</pre><pre>%Finding number of stages%%%%%%%%%%%%%%%%%%%%%%%%%%%%</pre><pre>n=0;<br>maxstagesallowed = 100;<br>stagepointsx = [];<br>stagepointsy = [Y1];</pre><pre>if stopsignal ==0<br>    %Finding whether eqm curve and op line intersect or not. <br>    intersects = @(x)(slopeopl*(x-X2)+Y2 - h(x));<br>    intrx = fzero(intersects, (X1+X2)/2);<br>    <br>    if intrx&gt;X2 &amp;&amp; intrx&lt;X1<br>        <br>        errormg = &#39;Liquid rate less than minimum. Please increase L2 and run again.&#39;<br>        app.RunstatusEditField.Value = errormg;<br>    else<br>        b = X1;<br>        stagepointsx = [stagepointsx, b];<br>        while n &lt; maxstagesallowed<br>            yy = h(b);<br>            stagepointsy = [stagepointsy, yy];<br>            <br>            xx = X2 + (yy-Y2)/slopeopl;<br>            stagepointsx = [stagepointsx, xx];<br>            <br>            if xx&gt;X2<br>                n = n+1;<br>                b = xx;<br>            else<br>                yy = h(xx);<br>                stagepointsy = [stagepointsy, yy];<br>                break<br>            end<br>        end<br>        app.RunstatusEditField.Value = &#39;Run successful. Check Results tab.&#39;;<br>    end    <br>end        <br>n = n+1;</pre><pre>%Plotting Equilibrium line and Operating line<br>opline = @(x)(slopeopl*(x-X2)+Y2);<br>Ye = opline(X);<br>hold (app.UIAxes,&#39;on&#39;)<br>plot(app.UIAxes, X, Ye);<br>plot(app.UIAxes, X, Y);</pre><pre>lx = length(stagepointsx)-1;</pre><pre>%Plotting stages<br>for j=1:lx<br>    p1 = [stagepointsx(j) stagepointsx(j)];<br>    p2 = [stagepointsy(j) stagepointsy(j+1)];<br>    plot(app.UIAxes, p1, p2);<br>    <br>    p3 = [stagepointsx(j) stagepointsx(j+1)];<br>    p4 = [stagepointsy(j+1) stagepointsy(j+1)];<br>    plot(app.UIAxes, p3, p4);<br>    <br>end<br>app.NumberofstagesEditField.Value = n;</pre><p>You can download the dot mlapp file from the link I have mentioned at the top.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7f3e78995652" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>