{"id":146,"date":"2019-05-16T10:06:03","date_gmt":"2019-05-16T18:06:03","guid":{"rendered":"https:\/\/linearcontrol.info\/fundamentals\/?p=146"},"modified":"2019-06-03T07:21:42","modified_gmt":"2019-06-03T15:21:42","slug":"simulating-linear-systems-with-non-zero-initial-conditions","status":"publish","type":"post","link":"https:\/\/linearcontrol.info\/fundamentals\/index.php\/2019\/05\/16\/simulating-linear-systems-with-non-zero-initial-conditions\/","title":{"rendered":"Simulating linear systems with non-zero initial conditions"},"content":{"rendered":"\n<p>I have discussed <a href=\"https:\/\/linearcontrol.info\/fundamentals\/index.php\/2019\/05\/16\/simulating-linear-systems-with-non-zero-initial-conditions-in-state-space\/\">in another post<\/a> how to work with state-space models to simulate the response of linear systems using Matlab&#8217;s <code>lsim<\/code>. It is however also possible to approach this problem from a transfer-function point of view without having to mess with state-space at all.<\/p>\n\n\n\n<!--more-->\n\n\n\n<p>In order to appreciate what is going on one needs to look at systems of order higher than one. How about the generic second-order system modeled by the ODE<\/p>\n\n\n\n<p>$$\\ddot{y}(t) + a_1 \\dot{y}(t) + a_2 y(t) = b_2 u(t)$$<\/p>\n\n\n\n<p>The transfer-function $G$ in this case is<\/p>\n\n\n\n<p>$$G(s) = \\frac{b_2}{s^2 + a_1 s + a_2}$$<\/p>\n\n\n\n<p>which is easily obtained with the help of the Laplace transform (See Chapter 3). More complex relationships involving derivatives of $u$ can be handled similarly as long as the resulting transfer-function remains proper (See Chapter 5).<\/p>\n\n\n\n<p>The Laplace transform also provides a way to formally incorporate initial conditions. Using the <em>differentiation in time<\/em> property from Table 3.2 one can write <\/p>\n\n\n\n<p>$$\\mathcal{L} \\{ y^{(n)}(t) \\} = s^n F(s) &#8211; s^{n-1}y(0) &#8211; \\cdots &#8211; y^{(n-1)}(0)$$<\/p>\n\n\n\n<p>which applied to the above transfer-function provides<\/p>\n\n\n\n<p>$$s^2 Y(s) &#8211; s y(0) &#8211; \\dot{y}(0) + a_1 (s Y(s) &#8211; y(0)) + a_2 Y(s) = b_2 U(s)$$<\/p>\n\n\n\n<p>Rearrange<\/p>\n\n\n\n<p>$$(s^2 + a_1 s + a_2) Y(s) = b_2 U(s) + (s + a_1) y(0) + \\dot{y}(0)$$<\/p>\n\n\n\n<p>and solve for $Y(s)$ to obtain<\/p>\n\n\n\n<p>$$Y(s) = G(s) U(s) + G_0(s)$$<\/p>\n\n\n\n<p>where $G$ is the transfer-function you are familiar with and<\/p>\n\n\n\n<p>$$G_0(s) = \\frac{(s + a_1) y(0) + \\dot{y}(0)}{s^2 + a_1 s + a_2}$$<\/p>\n\n\n\n<p>is a rational function related to the initial conditions, in this case $y(0)$ and $\\dot{y}(0)$. At this point one could simply invert $G_0$ and use linearity to add to the response. This can be done symbolically or by realizing that <\/p>\n\n\n\n<p>$$\\mathcal{L}^{-1} \\{ G_0(s) \\} = \\mathcal{L}^{-1} \\{ G_0(s) \\times 1 \\} = G_0 \\delta(t)$$<\/p>\n\n\n\n<p>so that this component can be calculated as an impulse response, that is<\/p>\n\n\n\n<p>$$y(t) = G u(t) + G_0 \\delta(t)$$<\/p>\n\n\n\n<p>Because $\\delta(t)$ is not a regular function you cannot use&nbsp;<code>lsim<\/code>&nbsp;to calculate that component of the response. Instead Matlab has the specialized function&nbsp;<code>impulse<\/code>&nbsp;that you can use. For example<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">y = lsim(G, u, t) + impulse(G0, t)<\/pre>\n\n\n\n<p>will do the job. Note that it is important to provide the vector&nbsp;<code>t<\/code>&nbsp;to the function&nbsp;impulse&nbsp;otherwise it will not return a vector compatible with the first vector calculated by&nbsp;<code>lsim<\/code>.<\/p>\n\n\n\n<p>These ideas can be extended to higher-order systems and a formula for the numerator of $G_0(s)$ can be constructed if wanted. Such formula is implicitly related to one state-space realization and the procedure outlined <a href=\"https:\/\/linearcontrol.info\/fundamentals\/index.php\/2019\/05\/16\/simulating-linear-systems-with-non-zero-initial-conditions-in-state-space\/\">here<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I have discussed in another post how to work with state-space models to simulate the response of linear systems using Matlab&#8217;s lsim. It is however also possible to approach this problem from a transfer-function point of view without having to mess with state-space at all.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false},"categories":[9],"tags":[51,52,12,10,11],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/linearcontrol.info\/fundamentals\/index.php\/wp-json\/wp\/v2\/posts\/146"}],"collection":[{"href":"https:\/\/linearcontrol.info\/fundamentals\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linearcontrol.info\/fundamentals\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linearcontrol.info\/fundamentals\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/linearcontrol.info\/fundamentals\/index.php\/wp-json\/wp\/v2\/comments?post=146"}],"version-history":[{"count":7,"href":"https:\/\/linearcontrol.info\/fundamentals\/index.php\/wp-json\/wp\/v2\/posts\/146\/revisions"}],"predecessor-version":[{"id":487,"href":"https:\/\/linearcontrol.info\/fundamentals\/index.php\/wp-json\/wp\/v2\/posts\/146\/revisions\/487"}],"wp:attachment":[{"href":"https:\/\/linearcontrol.info\/fundamentals\/index.php\/wp-json\/wp\/v2\/media?parent=146"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linearcontrol.info\/fundamentals\/index.php\/wp-json\/wp\/v2\/categories?post=146"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linearcontrol.info\/fundamentals\/index.php\/wp-json\/wp\/v2\/tags?post=146"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}