These videos and handouts are supplemental documents of paper X. Li, Z. Huang. An Inverted Classroom Approach to Educate MATLAB in Chemical Process Control, Education for Chemical Engineers, 9, -, 7. The copyright of these materials belongs to Dr. Huang and Villanova University, PA, USA. Any use of these materials should be in compliance with U.S. Copyright law, including the TEACH Act. These materials are only allowed for academic purpose, NOT for commercial usage.
CHE 43: Chemical Process Control, Spring 6, by Zuyi (Jacky) Huang, Villanova University MATLAB Training - Laplace Transform and Transfer Function Objective o Basic commands for Laplace transform and inverse Laplace transform to solve ODEs o Represent ODEs using transfer functions in Simulink o Prediction from transfer functions for first-order, second-order, lead-lag, higher-order and other complicated models Introduction of the commands for Laplace transform and inverse Laplace transform o Laplace transform and inverse Laplace transform Use command laplace and ilaplace to perform Laplace transform and inverse Laplace transform Example : get the inverse Laplace transform for the following terms and get the time profiles for them. -s + e ) H( (4s + )(3s + ) ) H ( s( s + 4s + 4) s( s + ) + s 3) H 3( ( s + s + ) Solution: General procedure: type the Laplace term using symbolic variable s, and then use the command to get the time t function. -s + e ) H( (4s + )(3s + ) >> syms s %Define s as a symbolic variable for inverse Laplace-Transform >> H (+ exp(-*)/(4*s+)/(3*s+); >> h_t ilaplace(h) You should get h_t exp(-t/4) - exp(-t/3) + heaviside(t - )*(exp(/ - t/4) - exp(/3 - t/3)) >> t :.:; >> h_t exp(-t/4)-exp(-t/3)+heaviside(t-).*(exp(/-t/4) - exp(/3 - t/3)); >> plot(t,h_t,'linewidth',); >> xlabel('time (','Fontsize',) >> ylabel('h','fontsize',).5 This line is used to highlight the dot. You don t need to type it in MATLAB..5 h..5 4 6 8 Time ( Note: you can save all these commands into a document, i.e., Main_example_.m, so that you just need to type Main_example_ in the command window again to get the simulation results. Here is
CHE 43: Chemical Process Control, Spring 6, by Zuyi (Jacky) Huang, Villanova University how you create a new script with the name of Main_example_.m: click New Script -> input all commands into the new script, and make sure that >> is not input in the new script -> press Ctrl + s on the keyboard to save the new script as Main_example_ -> type Main_example_ in the command window to run the simulation and plot the result Window for setting a new script: Save all the commands in a new script (i.e., Main_example_) Run the script in the command window: ) H ( s( s + 4s + 4) s( s + ) >> syms s %Define s as a symbolic variable for inverse Laplace- Transform >> H /s/(s + )^ >> h_t ilaplace(h) You should get h_t /4 - (t*exp(-*t))/ - exp(-*t)/4 >> t :.:; >> h_t /4 - (t.*exp(-*t))/ - exp(-*t)/4; >> plot(t,h_t,'linewidth',); >> xlabel('time (','Fontsize',) >> ylabel('h','fontsize',)
CHE 43: Chemical Process Control, Spring 6, by Zuyi (Jacky) Huang, Villanova University Save the program in a script named Main_example_ The profile of the output should be as follow: 3) + s H 3( ( s + s + ) >> syms s %Define s as a symbolic variable for inverse Laplace- Transform >> H3 (s+)/(s^ + s + ); >> h_t3 ilaplace(h3) You should get h_t3 exp(-t/)*(cos((3^(/)*t)/) + 3^(/)*sin((3^(/)*t)/)) >> t :.:; >> h_t3 exp(-t/).*(cos((3^(/)*t)/)+3^(/)*sin((3^(/)*t)/)); >> plot(t,h_t3,'linewidth',); >> xlabel('time (','Fontsize',) >> ylabel('h3','fontsize',) Save the program in a script named Main_example_3 The profile of the output should be as follow: 3
CHE 43: Chemical Process Control, Spring 6, by Zuyi (Jacky) Huang, Villanova University Example 3: get the time profile of the change of a chemical concentration (i.e., y, in the unit of nm) due to the change of the complicated inlet flowrates (shown in the right hand side of the equation) from the following differential equation: t d y dy + 3 + y e d + step( t - 5) + sin3t dt dt ò - t dy t with y() and ( ) dt Step : The Laplace transform of the left-hand side: s Y( + 3sY( + Y ( ( s + 3s + ) Y( Step : Get the Laplace transform of the right-hand side of the equation: >> syms tau t >> laplace(*int(exp(-tau),,t)+*heaviside(t-5)+sin(3*t)) Note: () the Laplace operation is defined as a symbolic operation, so you have to define tau and t as symbolic variables; () you can find the expressions for other functions in the following website http://www.mathworks.com/help/symbolic/functionlist.html The Laplace transform of the right-hand side turns out to be: (*exp(-5*)/s - /(s + ) + 3/(s^ + 9) + /s Step 3: get the Laplace transform of y(t) by dividing the coefficient term (s + 3s + ) on the Laplace transform of the right-hand side >> syms s; >> Y_s ((*exp(-5*)/s - /(s + )+3/(s^ + 9) + / / (s^ +3*s+ ) Step 4: apply inverse Laplace transform on Y( to get the time profile of y(t) >> y_t ilaplace(y_ The time profile of y is y_t (3*exp(-t))/ - (9*cos(3*t))/3 - (6*exp(-*t))/3 - (7*sin(3*t))/3 - *t*exp(-t) + *heaviside(t - 5)*(exp( - *t)/ - exp(5 - t) + /) + Step 5: plot the profile of y over time >> t :.:; >> y_t (3*exp(-t))/ - (9*cos(3*t))/3 - (6*exp(-*t))/3 - (7*sin(3*t))/3 - *t.*exp(-t) + *heaviside(t - 5).*(exp( - *t)/ - exp(5 - t) + /) + ;% this is one line in MATLAB >> plot(t,y_t,'linewidth',) >> xlabel('time (', 'fontsize', ); >> ylabel('y (nm)', 'fontsize', ); 4
CHE 43: Chemical Process Control, Spring 6, by Zuyi (Jacky) Huang, Villanova University.5 y (nm).5.5 4 6 8 Time ( Solve ODEs using transfer functions in Simulink o Represent transfer function in Simulink d y dy Example 4: We redo the example: + 3 + y e d + step( t - 5) + sin3t dt dt ò - t t in Simulink. d y dy Step : re-write the model as + 3 + y u( t), as we can get the input functions on dt dt the left-hand side of the equation in Simulink. Step : get the transfer function to link the input u to the output y: s Y( + 3sY( + Y ( U( ( s + 3s + ) Y( U( > Y( U ( s + 3s + Step 3: input the transfer function in Simulink, get the functions for s + 3s + t òe - t dt, step( t - 5), sin3t as the input of the transfer function, and simulate the model in Simulink to get the output profile for y o You can find the module for transfer function from the Continuous category. t 5
CHE 43: Chemical Process Control, Spring 6, by Zuyi (Jacky) Huang, Villanova University o Double-click to input the coefficient of s terms (from the highest order to the lowest) for both the numerator and denominator For the transfer function, the coefficients for the numerator and s + 3s + denominator are [] and [ 3 ] respectively. o Here is the procedure to add t ò - e t dt, the first term of the input signals on the right-hand side of the equation, into the Simulink model: get the exp(u) from the Math Operation category, and set the input u as t. Add the clock from the Sources category to get the variable t, which then times - to get t. Integrator is added from the Continuous category. Set the initial value of the Integrator to zero. o Add step( t -5), sin 3t from the Sources category into the Simulink model. Set the final value, the initial value, and the step time of the step signal step(t-5) as,, and 5 respectively. For the sin3t, set the Amplitude as and the Frequency as 3. o Add the workspace for the time t and the output y_t. Make sure that you should change the variable names to t and y_t with the Save format as Array. Otherwise, you can plot the profile of y_t versus t. 6
CHE 43: Chemical Process Control, Spring 6, by Zuyi (Jacky) Huang, Villanova University o Set the Stop time as minutes, and the solver as ode5s. Run the simulation and plot the y profile. We plot the profile of the output y with the one obtained from the Laplace transform approach in the same figure. Here are the steps you should use to plot the output profiles from the Laplace transform (i.e., t VS y_t) and the Simulink model (i.e., t VS y_t). ) Run the Simulink model to get the profiles for t and y_t. ) Run the following commands to get the profiles. 3) Save the figure in the *.jpg format and insert into the WORD document. >> syms tau t >> laplace(*int(exp(-tau),,t)+*heaviside(t-5)+sin(3*t)) >> sys s;%define s as a symbolic variable for inverse Laplace-Transform >> Y_s ((*exp(-5*)/s - /(s + )+3/(s^ + 9) + / / (s^ +3*s+ ) >> y_t ilaplace(y_ >> t :.:; % Specify the time >> y_t (3*exp(-t))/ - (9*cos(3*t))/3 - (6*exp(-*t))/3 - (7*sin(3*t))/3 - *t.*exp(-t) + *heaviside(t - 5).*(exp( - *t)/ - exp(5 - t) + /) + ; % this one line >> plot(t,y_t,'linewidth',) >> hold on; >> plot(t,y_t,'r+', 'linewidth',) >> xlabel('time (Minute', 'fontsize', ); >> ylabel('y (nm)', 'fontsize', ); >> legend ('Laplace Transform approach','simulink simulation approach') Here are the profiles you should get: 7
CHE 43: Chemical Process Control, Spring 6, by Zuyi (Jacky) Huang, Villanova University Prediction from transfer functions for first-order, second-order, lead-lag, higher-order and other complicated models Model prediction for first order plus time delay systems Example 5: Liquid storage system with a long transmission line can be described by a first order plus time delay model:! " # $h $&! "( ) h where R v is the valve coefficient. min/m, A is the cross-section area of the tank 4 m, q i is in-let flow rate. The steady state value for q i and h are 4 m 3 /min and.4 m respectively. Determine the time profile of h..8.6 q in (m 3 /min).4. Solution: 5 5 Time (minute 8
CHE 43: Chemical Process Control, Spring 6, by Zuyi (Jacky) Huang, Villanova University The deviation ODE model is! " # $h $&! "( ) h where q i is q i q i () as shown in the following figure.4.3. q in ' (m 3 /min). 5 5 Time (minute After performing Laplace transform on the deviation ODE, we can get the following transfer function:, -! ".! " #. + )(.) Now we can use Simulink to get the profile of h upon the change in q i : Step : Instead of decomposing the q i as the summation of two step functions, use the Signal Builder in the Sources category to get the profile of q i. o Double click Signal Builder to pick the pulse signal, change the time Range to minutes. The default time unit in the Signal Builder is second. We don t have to change it to minute here, although the unit should be minute. 9
CHE 43: Chemical Process Control, Spring 6, by Zuyi (Jacky) Huang, Villanova University o Set the duration and amplitude for the pulse signal with the following procedure: ) move the mouse around the top line of pulse and left-click it ; ) after selecting the top line, double left-click the line to set the duration and amplitude of the pulse. This line should be in BOLD format for editing The beginning time for the pulse: the nd minute The ending time for the pulse: the 6 th minute The amplitude of the pulse is set to.4 m 3 /min o Check the profile from the scope or plot the output profile of the Signal Builder. In the scope, you should get the following figure: Step : Generate the transfer function in the Simulink and link the input (i.e., the output of the Signal Builder) to the transfer function. 5 o The transfer function should be 6 ;.: ; 5 6 789: ;.89:
CHE 43: Chemical Process Control, Spring 6, by Zuyi (Jacky) Huang, Villanova University o Add the output of the transfer function, i.e., h, with the initial value of h, i.e., h ().4 m. After this, we can get h (t) h () + h (t). o Save the output h in the workspace. o Add the time signal from the sources category and save the time in the workspace Step 3: Plot the result of h over time by using the following commands to plot the output profile. >> plot(t,h,'linewidth',) >> xlabel('time (minute','fontsize', ) >> ylabel('h (m)','fontsize', ) Model prediction for second order systems Example 6: The temperature in a heat-exchanger, represented by the variable y, can be described by the following equation in which u is the electrical heating power. K is a coefficient that can be manipulated by changing the cooling methods. The steady state value for y and u are 3 o C and W respectively. Predict the profile of y when the heating power u increases from to 5 W at time zero for K equal to, 4, and 8. Simulate the model for 5 minutes. Solution: The ODE can be re-written in the deviation variable form: $ >? $& > + @ $? + 4? B $& The transfer function from the deviation ODE is: / 4 / 4 Y' ( u'( u'( u'( 4 s + Ks + K s + s + t s + tzs + 4 4 The procedure to implement the model in Simulink: Step : For K, input the transfer function and step input in Simulink. Make sure that the input, u (t), is a step with a zero initial value and a 3 W final value.
CHE 43: Chemical Process Control, Spring 6, by Zuyi (Jacky) Huang, Villanova University Step : Add the output y with its initial value, i.e., y y + 3, and save it into the workspace y ; add the time t signal into the Simulink model. Step 3: Apply the same approach to K equal to 4 and get profile y. Similarly, get the profile y 3 for K equal to 8. You can copy the module for y for y and y 3. You can put the modules for three outputs together in the same Simulink model. Note: to copy the entire module, select the module, press Ctrl on the keyboard and at the same time use the mouse to draw the module.
CHE 43: Chemical Process Control, Spring 6, by Zuyi (Jacky) Huang, Villanova University Step 4: Plot the three profiles, i.e., y, y, and y 3, together. >> plot(t,y,'r','linewidth',) >> hold on; >> plot(t,y,'b','linewidth',) >> hold on; >> plot(t,y3,'k','linewidth',) >> xlabel('time (minute','fontsize',) >> ylabel('y (^oc)','fontsize',) >> legend('k ','K 4','K 8','fontsize',) Model prediction for lead-lag systems (including inverse response system Example 7: Lead-lag systems can be presented by the following transfer function K(+ t 3 Y( U( (+ t (+ t where t > 3t. Assume that t 4, t, and K, plot the output profiles for t 3 6, 4,, and -4 for a unit step change in the input u. Assume the initial value of y is zero. Simulate the model for 3 minutes. Solution: Step : Get the transfer function for t 3 6, add the time signal t in the Simulink model, add the unit step input, and save the output of the transfer function y in the workspace; Step : Repeat Step for t 3 4,, and -4, and save the output to y, y 3 and y 4. 3
CHE 43: Chemical Process Control, Spring 6, by Zuyi (Jacky) Huang, Villanova University Step 3: Plot all the output profiles together in the same figure using the following commands: >> plot(t,y,'r','linewidth',) >> hold on; >> plot(t,y,'b','linewidth',) >> hold on; >> plot(t,y3,'k','linewidth',) >> hold on; >> plot(t,y4,'k','linewidth',) >> xlabel('time (minute','fontsize',) >> ylabel('y','fontsize',) >> legend('\tau_3 6','\tau_3 4','\tau_3 ','\tau_3 ','fontsize',) Example 8: A change in the steam pressure to the reboiler will lead to inverse response in the reboiler level. In Process (G ), a steam pressure increase leads to more vapor flow which can cause a rapid spillover of liquid from some trays to the reboiler (fast effect). In Process (G ), removing significant amount of the liquid mixture from the reboiler is through increased boiling, that is, more steam will lead to a lower liquid level in the reboiler over time (slow effect). U( + + Y( 4
CHE 43: Chemical Process Control, Spring 6, by Zuyi (Jacky) Huang, Villanova University Assume K 3, t, K -6, t. Predict the change of liquid level (i.e., y) due to a step change of psi in the steam pressure (i.e., u) for 8 minutes. Assume the system is at steadystate at the beginning. Solution: Step : build the two first-order models and add them together, add the step change with psi as the final value and zero as the initial value, add the time signal, and save the time t and the output y into the Workspace. Step : run the simulation for 8 minutes, and plot the output y profile by the following commands: >> plot(t,y,'r','linewidth',) >> xlabel('time (minute','fontsize',) >> ylabel('y (mm)','fontsize',) y (mm) - - Model prediction for model simplification -3 4 6 8 Time (minute Example 9 The reboiler in a distillation column is heated up by steam which is supplied from a tank heated by electrical power. To design a controller to control the liquid level in the tank, you need to get the transfer function for the controlled objects in the loop and then simplify the transfer function to the first order plus time delay model (as most available controller design methods were developed for first order plus time delay system). q: electrical power G Q: heating power G V: steam pressure ( -s + ).5s + 3 s G + 3 5s + Controller Heating element Steam creator Reboilor L: liquid level The transfer function from q to L is: ( -s + ) L ( q( (.5s + ) (3s + ) (5s + ) 5
CHE 43: Chemical Process Control, Spring 6, by Zuyi (Jacky) Huang, Villanova University The simplified model via Taylor series expansion approach is: -4.5s e L( q( 5s + The simplified model via the Skogestad s half rule is: -3s e L3( q( 6.5s + Compare the output profiles for these three transfer functions when the electrical power has a step change of 5 W at time zero. Simulate the model for 5 minutes Solution: Step : Input the model L in the Simulink, the time signal t, and record the output as L in the Workspace; Step : Input the model L and L 3 in the Simulink o Both models have a delay term. o Add the delay term Transport Delay from Continuous category, and set the delay time 4.5 for L and 3 for L 3. 6
CHE 43: Chemical Process Control, Spring 6, by Zuyi (Jacky) Huang, Villanova University Step 3: Simulate the model for 5 minutes and plot the output profiles for the three models together. >> plot(t,l,'r','linewidth',) >> hold on; >> plot(t,l,'b','linewidth',) >> hold on; >> plot(t,l3,'k','linewidth',) >> xlabel('time (minute','fontsize',) >> ylabel('l (mm)','fontsize',) >> legend('l model','l model','l3 model') 8 6 L model L model L3 model L (mm) 4-3 4 5 Time (minute 7