• No results found

Numerically inverting the Laplace transform

In document Advanced Control using MATLAB (Page 53-56)

From differential to difference equations

2.4 Inversion of z-transforms

2.4.5 Numerically inverting the Laplace transform

---6 zˆ2 - 1.25 z + 0.25 Sampling time: 1

>> y=impulse(sysd) % compute the impulse response

11 y =

0 10.0000 17.5000 19.3750

16 19.8438 19.9609

Finally, the contour integral method can also be used to invert z-transforms, [148, §3–3], but Seborg et al maintains it is seldom used in engineering practice, [179, p571] because it is fraught with numerical implementation difficulties. These difficulties are also present in the continuous equivalent; some of which are illustrated in the next section.

2.4.5 Numerically inverting the Laplace transform

Surprisingly, the numerical inversion of continuous transfer functions is considered far less impor-tant than the computation of the inverse of discrete transfer functions. This is fortunate because the numerical inversion of Laplace transforms is devilishly tricky. Furthermore, it is unlikely that you would ever want to numerically invert a Laplace transform in control applications, since most problems involver little more than a rational polynomial with a possible exponential term.

For these problems we can easily factorise the polynomial and use partial fractions or use the steporimpulseroutines for continuous linear responses.

However in the rare cases where we have a particularly unusual F (s) which we wish to convert back to the time domain, we might be tempted to use the analytical expression for the inverse directly

f (t) = 1 2πj

Z σ+j∞

σ−j∞

F (s) estds (2.17)

where σ is chosen to be larger than the real part of any singularity of F (s). Eqn.2.17is sometimes known as the Bromwich integral or Mellin’s inverse formula.

The following example illustrates a straight forward application of Eqn.2.17to invert a Laplace transform. However be warned that for all but the most well behaved rational polynomial exam-ples this strategy is not to be recommended as it results in severe numerical roundoff error due to poor conditioning.

Suppose we try to numerically invert a simple Laplace transform, F (s) = 3

s(s + 5)←→ f(t) = 3

5 1− e−5t

with a corresponding simple time solution. We can start by defining an anonymous function of the Laplace transform to be inverted.

Fs = @(s) 3.0./(s+5)./s; %Laplace function to invert F (s) = 3/(s(s + 5)) . . . Fsexp = @(s,t) Fs(s).*exp(s*t) %and associated integrand F (s)est

Now since the largest singularity of F (s) is 0, we can choose the contour path safely to be say σ = 0.1. We can also approximate the infinite integration interval by reasonably large numbers.

It is convenient that the MATLABroutineintegralworks directly in the complex domain.

c = 0.1; %Value σ > than any singularities of F (s) a = c-100j; b = c+200j; %Contour path approx: σ− j∞ to σ + j∞

3

t=linspace(0,8); %time range of interest

%Numerically approximate Eqn.2.17.

ft = 1./(2*pi*1j)*arrayfun(@(t) integral(@(x) Fsexp(x,t),a,b), ti);

plot(t,ft) %Compare results in Fig.2.10(a).

Due to small numerical roundoff however, the returned solution has a small imaginary compo-nent, which we can in this instance safely ignore. In this rather benign example, where we know the analytical solution, we can validate the accuracy as shown in Fig.2.10(a), which it has to be admitted, is not that wonderful. We should also note in the simplistic implementation above we have not adequately validated that our algorithmic choices such as the finite integration limits are appropriate, so we should treat any subsequent result with caution. In fact if you repeat this calculation with a larger value of σ, or a smaller integration range such as say 1− 10j to 1 + 10j then the quality of the solution drops alarmingly. One way to improve the integration accuracy is to use thewaypointsoption in theintegralroutine.

Over the years there have been many attempts to improve the inversion strategy as reviewed in [1], but nearly all of the proposals run into the problem of precision. For example, Fig.2.11 shows the problem when attempting to invert F (s) = 1/√

s2+ 1 using the Gaver-Stehfest ap-proximation algorithm with a varying number of terms. The Gaver-Stehfest family of schemes are well known to produce inaccurate results for underdamped systems, but when we increase the number of terms in an attempt to improve the accuracy, the results deteriorate due to numer-ical round off. Directly applying the Bromwich integral to this transform as shown in Fig.2.10(b) is no better. While the strategy suggested in [1] seemingly circumvents the problem of precision, it does so by brute-force using multi-precision arithmetic which is hardly elegant.

An alternative numerical algorithm is the inverse Laplace transform functioninvlapfunction contributed by Karl Hollenbeck from the Technical University of Denmark. You can test this routine using one of the following Laplace transform pairs in Table2.3. The first two are standard, those following are more unusual. A more challenging collection of test transforms is given in [1].

The numerical solution toL−1n

1

se−1/so

is compared with the analytical solution from Table2.3 in Fig.2.12using a modest tolerance of 10−2. The routine splits the time axis up into decades, and inverts each separately which is why we can see some numerical noise starting at t = 10.

All of these numerical inversion strategies, starting from the direct application of the Bromwich

0 2 4 6 8

(a) Inverting a benign transfer function, L−1n

(b) Inverting a challenging transfer function, L−1



1 s2+1



Figure 2.10: Numerically inverting Laplace transforms by direct evaluation of the Bromwich integral. Since this strategy is suspectable to considerable numerical errors, it is not to be recom-mended.

Figure 2.11: Demonstrating the precision problems when numerically inverting the Laplace transform using the Gaver-Stehfest algorithm with a varying number of terms. The exact inversion is the red solid line while the approximate inversion is given by –◦–.

Table 2.3: A collection of Laplace transform pairs suitable for testing numerical inversion strate-gies.

Description F (s) f (t) Comment

Easy test 1/s2 t

Control TF 1

(s + 2)(s + 3)

1

2 e−t− e−3t

Oscillatory 1

√s2+ 1 J0(t) Bessel function, see Fig.2.10(b)& Fig.2.11.

Nasty 1

√se−1/s 1πtcos(√

4t), See Fig.2.12.

Figure 2.12: Testing the numerical inver-sion of the Laplace transform e−1/s/√s us-ing theinvlaproutine.

−0.5 0 0.5 1 1.5

f(t) L−1nexp(−1/s)

s

o

0 5 10 15 20 25 30 35 40

10−6 10−4 10−2 100

error

time

integral in Eqn.2.17, the Gaver-Stehfest algorithm and variants and the implementationinvlap require some care to get reasonable results. Unfortunately in practical cases it can be difficult to choose suitable algorithmic tuning constants, which mean that it is difficult to generate any sort of error bound on the computed curve.

In document Advanced Control using MATLAB (Page 53-56)