Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 51 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
51
Dung lượng
435,25 KB
Nội dung
250 NUMERICAL DIFFERENTIATION/ INTEGRATION (ii) Add the block of statements in P5.5(c) into the routines “smp- sns() ”and“adap_smpsn()” to make them cope with the cases of NaN (Not-a-Number) and Inf (Infinity). (iii) Supplement the program “ nm5p06a.m” so that the various routines are applied for computing the integrals (P5.6.1) and (P5.6.3), where the parameters like the number of segments (N = 200), the error tolerance (tol = 1e-4), and the number of grid points (MGL = 20) are supposed to be used as they are in the program. Noting that the second integrand function in (P5.6.3) oscillates like crazy with higher frequency and larger amplitude as y gets closer to zero (0), set the lower bound of the integration interval to a2 = 0.001. (iv) Run the supplemented program and fill in Table P5.6 with the absolute errors of the results. %nm5p06a warning off MATLAB:divideByZero fp56a = inline(’sin(x)./x’,’x’); fp56a2 = inline(’sin(1./y)./y’,’y’); IT = pi/2; % True value of the integral a = 0; b = 100; N = 200; tol = 1e-4; MGL = 20; a1 = 0; b1 = 1; a2 = 0.001; b2 = 1; format short e e_s = smpsns(fp56a,a,b,N)-IT e_as = adapt_smpsn(fp56a,a,b,tol)-IT e_ql = quadl(fp56a,a,b,tol)-IT e_GL = Gauss_Legendre(fp56a,a,b,MGL)-IT e_ss = smpsns(fp56a,a1,b1,N) + smpsns(fp56a2,a2,b2,N)-IT e_Iasas = adapt_smpsn(fp56a,a1,b1,tol)+ ???????????????????????????? -IT e_Iqq = quad(fp56a,a1,b1,tol)+??????????????????????????? -IT warning on MATLAB:divideByZero %nm5p06b warning off MATLAB:divideByZero fp56b = inline(’exp(-x.*x)’,’x’); fp56b1 = inline(’ones(size(x))’,’x’); fp56b2 = inline(’exp(-1./y./y)./y./y’,’y’); a = 0; b = 200; N = 200; tol = 1e-4; IT = sqrt(pi)/2; a1=0;b1=1;a2=0;b2=1;MGH=2; e_s = smpsns(fp56b,a,b,N)-IT e_as = adapt_smpsn(fp56b,a,b,tol)-IT e_q = quad(fp56b,a,b,tol)-IT e_GH = Gauss_Hermite(fp56b1,MGH)/2-IT e_ss = smpsns(fp56b,a1,b1,N) + smpsns(fp56b2,a2,b2,N)-IT Iasas = adapt_smpsn(fp56b,a1,b1,tol)+ +????????????????????????????? -IT e_qq = quad(fp56b,a1,b1,tol)+????????????????????????? -IT warning off MATLAB:divideByZero PROBLEMS 251 Table P5.6 Results of Applying Various Numerical Integration Methods for Improper Integrals Simpson adaptive quad Gauss S&S a&a q&q (P5.6.1) 8.5740e-3 1.9135e-1 1.1969e+0 2.4830e-1 (P5.6.2) 6.6730e-6 0.0000e+0 3.3546e-5 (b) To apply the routines like “smpsns()”, “adapt_smpsn()”, “quad()”, and “ Gauss_Hermite()” for evaluatingthe integral (P5.6.2), do the following. (i) Note that the integration interval [0, ∞) can be changed into a finite interval as below. ∞ 0 e −x 2 dx = 1 0 e −x 2 dx + ∞ 1 e −x 2 dx = 1 0 e −x 2 dx + 0 1 e −1/y 2 − 1 y 2 dy = 1 0 e −x 2 dx + 1 0 e −1/y 2 y 2 dy (P5.6.4) (ii) Compose the incomplete routine “ Gauss_Hermite” like “Gauss_ Legendre ”, which performs the Gauss–Hermite integration intro- duced in Section 5.9.2. (iii) Supplement the program “ nm5p06b.m” so that the various routines are applied for computing the integrals (P5.6.2) and (P5.6.4), where the parameters like the number of segments (N = 200), the error tolerance ( tol = 1e-4) and the number of grid points (MGH = 2) are supposed to be used as they are in the program. Note that the integration interval is not (−∞, ∞) like that of Eq. (5.9.12), but [0, ∞) and so you should cut the result of “ Gauss_Hermite()”by half to get the right answer for the integral (P5.6.2). (iv) Run the supplemented program and fill in Table P5.6 with the absolute errors of the results. (c) Based on the results listed in Table P5.6, answer the following questions: (i) Among the routines “ smpsns()”, “adapt_smpsn()”, “quad()”, and “ Gauss()”, choose the best two ones for (P5.6.1) and (P5.6.2), respectively. (ii) The routine “ Gauss–Legendre()” works (badly, perfectly) even with as many as 20 grid points for (P5.6.1), while the routine 252 NUMERICAL DIFFERENTIATION/ INTEGRATION “Gauss_Hermite()” works (perfectly, badly) just with two grid points for (P5.6.2). It is because the integrand function of (P5.6.1) is (far from, just like) a polynomial, while (P5.6.2) matches Eq. (5.9.11) and the part of it excluding e −x 2 is (just like, far from) a polynomial. function I = Gauss_Hermite(f,N,varargin) [t,w]=???????(N); ft = feval(f,t,varargin{:}); I = w*ft’; (iii) Run the following program “nm5p06c.m” to see the shapes of the integrand functions of (P5.6.1) and (P5.6.2) and the second inte- gral of (P5.6.3). You can zoom in/out the graphs by clicking the Tools/Zoom in menu and then clicking any point on the graphs with the left/right mouse button in the MATLAB graphic win- dow. Which one is oscillating furiously? Which one is oscillating moderately? Which one is just changing abruptly? %nm5p06c clf fp56a = inline(’sin(x)./x’,’x’); fp56a2 = inline(’sin(1./y)./y’,’y’); fp56b = inline(’exp(-x.*x)’,’x’); x0 = [eps:2000]/20; x = [eps:100]/100; subplot(221), plot(x0,fp56a(x0)) subplot(223), plot(x0,fp56b(x0)) subplot(222), y = logspace(-3,0,2000); loglog(y,abs(fp56a2(y))) subplot(224), y = logspace(-6,-3,2000); loglog(y,abs(fp56a2(y))) (iv) The adaptive integration routines like “adapt smpsn()”and “ quad()” work (badly, fine) for (P5.6.1), but (fine, badly) for (P5.6.2). From this fact, we might conjecture that the adaptive integration routines may be (ineffective, effective) for the integrand functions which have many oscillations, while they may be (effective, ineffective) for the integrand functions which have abruptly changing slope. To support this conjecture, run the following program “ nm5p06d”, which uses the “quad()” routine for the integrals b 1 sin x x dx with b = 100, 1000, 10000 (P5.6.5a) 1 a sin(1/y) y dy with a = 0.001, 0.0001, 0.00001, (P5.6.5b) PROBLEMS 253 %nm5p06d fp56a = inline(’sin(x)./x’,’x’); fp56a2 = inline(’sin(1./y)./y’,’y’); syms x IT2 = pi/2 - double(int(sin(x)/x,0,1)) %true value of the integral disp(’Change of upper limit of the integration interval’) a = 1; b = [100 1e3 1e4 1e7]; tol = 1e-4; for i = 1:length(b) Iq2 = quad(fp56a,a,b(i),tol); fprintf(’With b = %12.4e, err_Iq = %12.4e\n’, b(i),Iq2-IT2); end disp(’Change of lower limit of the integration interval’) a2 = [1e-3 1e-4 1e-5 1e-6 0]; b2 = 1; tol = 1e-4; for i = 1:5 Iq2 = quad(fp56a2,a2(i),b2,tol); fprintf(’With a2=%12.4e, err_Iq=%12.4e\n’, a2(i),Iq2-IT2); end Does the “quad()” routine work stably for (P5.6.5a) with the changing value of the upper-bound of the integration interval? Does it work stably for (P5.6.5b) with the changing value of the lower-bound of the integration interval? Do the results support or defy the conjecture? (cf) This problem warns us that it may be not good to use only one routine for a computational work and suggests us to use more than one method for cross check. 5.7 Gauss–Hermite Integration Method Consider the following integral: ∞ 0 e −x 2 cos xdx = √ π 2 e −1/4 (P5.7.1) Select a Gauss quadrature suitable for this integral and apply it with the number of grid points N=4as well as the routines “smpsns()”, “ adapt_smpsn()”, “quad()”, and “quadl()” to evaluate the integral. In order to compare the number of floating-point operations required to achieve almost the same level of accuracy, set the number of segments for Simpson method to N = 700 and the error tolerance for all other routines to tol = 10 −5 . Fill in Table P5.7 with the error results. Table P5.7 The Results of Applying Various Numerical Integration Methods Simpson ( N = 700) adaptive ( tol = 10 −5 ) Gauss quad ( tol = 10 −5 ) quadl ( tol = 10 −5 ) (P5.7.1) |error| 1.0001e-3 1.0000e-3 flops 4930 5457 1484 11837 52590 (with quad8) (P5.8.1) |error| 1.3771e-2 0 4.9967e-7 flops 5024 7757 131 28369 75822 254 NUMERICAL DIFFERENTIATION/ INTEGRATION 5.8 Gauss–Laguerre Integration Method (a) As in Section 5.9.1, Section 5.9.2, and Problem 5.6(b), compose the MATLAB routines: “ Laguerp()”, which generates the Laguerre poly- nomial (5.9.18); “ Gausslgp()”, which finds the grid point t i ’s and the coefficient w N,i ’s for Gauss–Laguerre integration formula (5.9.16); and “ Gauss_Laguerre(f,N)”, which uses these two routines to carry out the Gauss–Laguerre integration method. (b) Consider the following integral: ∞ 0 e −t tdt =−e −t t ∞ 0 + ∞ 0 e −t dt =−e −t ∞ 0 = 1 (P5.8.1) Noting that, since this integral matches Eq. (5.9.17) with f(t) = t, Gauss–Laguerre method is the right choice, apply the routine “ Gauss_Laguerre(f,N)” (manufactured in (a)) with N = 2aswellas the routines “ smpsns()”, “adapt_smpsn()”, “quad()”, and “quadl()” for evaluating the integral and fill in Table P5.7 with the error results. Which turns out to be the best? Is the performance of “ quad()” improved by lowering the error tolerance? (cf) This illustrates that the routine “adapt_smpsn()” sometimes outperforms the MATLAB built-in routine “ quad()” with fewer computations. On the other hand, Table P5.7 shows that i t is most desirable to apply the Gauss quadrature schemes only if one of them is applicable to the integration problem. 5.9 Numerical Integrals Consider the following integrals. (1) π/2 0 x sin xdx = 1 (2) 1 0 x ln(sin x)dx =− 1 2 π 2 ln 2 (3) 1 0 1 x(1 − ln x) 2 dx = 1 (4) ∞ 1 1 x(1 + ln x) 2 dx = 1 (5) 1 0 1 √ x(1 + x) dx = π 2 (6) ∞ 1 1 √ x(1 + x) dx = π 2 (7) 1 0 ln 1 x dx = √ π 2 (8) ∞ 0 √ xe −x dx = √ π 2 (9) ∞ 0 x 2 e −x cos xdx =− 1 2 (a) Apply the integration routines “ smpsns()” (with N = 10 4 ), “adapt_ smpsn() ”, “quad()”, “quadl()”(tol= 10 −6 )and“Gauss_leg- endre() ” (Section 5.9.1) or “Gauss_Laguerre()” (Problem 5.8) (with N = 15) to compute the above integrals and fill in Table P5.9 with the relative errors. Use the upper/lower bounds of the integration interval in Ta ble P5.9 if they are specified in the table. (b) Based on the results listed in Table P5.9, answer the following questions or circle the right answer. PROBLEMS 255 (i) From the fact that the Gauss–Legendre integration scheme worked best only f or (1), it is implied that the scheme is (recommendable, not recommendable) for the case where the integrand function is far from being approximated by a polynomial. (ii) From the f act that the Gauss–Laguerre integration scheme worked best only f or (9), it is implied that the scheme is (recommendable, not recommendable) for the case where the integrand function excluding the multiplying term e −x is far from being approximated by a polynomial. (iii) Note the following: ž The integrals (3) and (4) can be converted into each other by a variable substitution of x = u −1 , dx =−u −2 du. The integrals (5) and (6) have the same relationship. ž The integrals (7) and (8) can be converted into each other by a variable substitution of u = e −x , dx =−u −1 du. From the results for (3)–(8), it can be conjectured that the numerical integra- tion may work (better, worse) if the integration interval is changed from [1, ∞) into (0,1] through the substitution of variable like x = u −n ,dx=−nu −(n+1) du or u = e −nx ,dx=−(nu) −1 du (P5.9.1) Table P5.9 The Relative Error Results of Applying Various Numerical Integration Methods Simpson Adaptive Gauss quad quadl (N = 10 4 ) (tol = 10 −6 ) (N = 10) (tol = 10 −6 ) (tol = 10 −6 ) (1) 1.9984e-15 0.0000e+00 7.5719e-11 (2) 2.8955e-08 1.5343e-06 (3) 9.7850e-02 (a = 10 −4 ) 1.2713e-01 2.2352e-02 (4), b = 10 4 9.7940e-02 9.7939e-02 (5) 1.2702e-02 (a = 10 −4 ) 3.5782e-02 2.6443e-07 (6), b = 10 3 4.0250e-02 4.0250e-02 (7) 6.8678e-05 5.1077e-04 3.1781e-07 (8), b = 10 1.6951e-04 1.7392e-04 (9), b = 10 7.8276e-04 2.9237e-07 7.8276e-04 5.10 The BER (Bit Error Rate) Curve of Communication with Multidimensional Signaling For a communication system with multidimensional (orthogonal) signaling, the BER—that is, the probability of bit error—is derived as P e,b = 2 b−1 2 b − 1 1 − 1 √ π ∞ −∞ (Q M−1 (− √ 2y − √ bSNR))e −y 2 dy (P5.10.1) 256 NUMERICAL DIFFERENTIATION/ INTEGRATION where b is the number of bits, M = 2 b is the number of orthogonal wave- forms, SNR is the signal-to-noise-ratio, and Q(·) is the error function defined by Q(x) = 1 √ 2π ∞ x e −y 2 /2 dy (P5.10.2) We want to plot the BER curves for SNR = 0:10[dB] and b = 1:4. (a) Consider the following program “ nm5p10.m”, whose objective is to compute the values of P e,b (SNR,b)forSNR= 0:10[dB] and b = 1:4 by using the routine “ Gauss_Hermite()” (Problem 5.6) and also by using the MATLAB built-in routine “ quad()” and to plot them versus SNR[dB] = 10 log 10 SNR. Complete the incomplete part which com- putes the integral in (P5.10.1) over [−1000, 1000] and run the program to obtain the BER curves like Fig. P5.10. (b) Of the two routines, which one is faster and which one presents us with more reliable values of the integral in (P5.10.1)? 10 10 0 10 −2 P e, b (SNR, b ) 10 −4 234567 109SNR [dB] b = 1 b = 2 b = 3 b = 4 Figure P5.10 The BER (bit error rate) curves for multidimensional (orthogonal) signaling. %nm5p10.m: plots the probability of bit error versus SNRbdB fs =’Q(-sqrt(2)*x - sqrt(b*SNR)).^(2^b - 1)’; Q = inline(’erfc(x/sqrt(2))/2’,’x’); f = inline(fs,’x’,’SNR’,’b’); fex2 = inline([fs ’.*exp(-x.*x)’],’x’,’SNR’,’b’); SNRdB = 0:10; tol = 1e-4; % SNR[dB] and tolerance used for ’quad’ for b = 1:4 tmp = 2^(b - 1)/(2^b - 1); spi = sqrt(pi); for i = 1:length(SNRdB), SNR = 10^(SNRdB(i)/10); Pe(i) = tmp*(1-Gauss_Hermite(f,10,SNR,b)/spi); Pe1(i) = tmp*(1-quad(fex2,-10,10,tol,[],SNR,b)/spi); Pe2(i) = tmp*(1-?????????????????????????????????)/spi); end semilogy(SNRdB,Pe,’ko’,SNRdB,Pe1,’b+:’,SNRdB,Pe2,’r ’), hold on end PROBLEMS 257 5.11 Length of Curve/Arc: Superb Harmony of Numerical Derivative/Integral. The graph of a function y = f(x) of a variable x is generally a curve and its length over the interval [a, b]onthex-axis can be described by a line integral as I = b a dl = b a dx 2 + dy 2 = b a 1 +(dy/dx) 2 dx = b a 1 +(f (x)) 2 dx (P5.11.1) For e xample, the length of the half-circumference of a circle with the radius of unit length can be obtained from this line integral with y = f(x) = 1 −x 2 ,a=−1,b= 1 (P5.11.2) Starting from the program “ nm5p11.m”, make a program that uses the numerical integration routines “ smpsns()”, “adapt_smpsn()”, “quad()”, “ quadl()”, and “Gauss_Legendre()” to evaluate the integral (P5.11.1,2) with the first derivative approximated by Eq. (5.1.8), where the parame- ters like the number of segments ( N), the e rror tolerance (tol), and the number of grid points ( M) are supposed to be as they are in the pro- gram. Run the program with the step size h = 0.001, 0.0001, and 0.00001 in the numerical derivative and fill in Table P5.11 with the errors of the results, noting that the true value of the half-circumference of a unit circle is π. %nm5p11 a=-1;b=1;%thelower/upper bounds of the integration interval N = 1000 % the number of segments for the Simpson method tol = 1e-6 % the error tolerance M = 20 % the number of grid points for Gauss–Legendre integration IT = pi; h = 1e-3 % true integral and step size for numerical derivative flength = inline(’sqrt(1 + dfp511(x,h).^2)’,’x’,’h’);%integrand P5.11.1) Is = smpsns(flength,a,b,N,h); [Ias,points,err] = adapt_smpsn(flength,a,b,tol,h); Iq = quad(flength,a,b,tol,[],h); Iql = quadl(flength,a,b,tol,[],h); IGL = Gauss_Legendre(flength,a,b,M,h); function df = dfp511(x,h) % numerical derivative of (P5.11.2) if nargin < 2, h = 0.001; end df = (fp511(x + h)-fp511(x - h))/2/h; %Eq.(5.1.8) function y = fp511(x) y = sqrt(max(1-x.*x,0)); % the function (P5.11.2) 258 NUMERICAL DIFFERENTIATION/ INTEGRATION Table P5.11 Results of Applying Various Numerical Integration Methods for (P5.11.1,2)/(P5.12.1,2) Step-size h Simpson Adaptive quad quadl Gauss (P5.11.1,2) 0.001 4.6212e-2 2.9822e-2 8.4103e-2 0.0001 9.4278e-3 9.4277e-3 0.00001 2.1853e-1 2.9858e-3 8.4937e-2 (P5.12.1,2) 0.001 1.2393e-5 1.3545e-5 0.0001 8.3626e-3 5.0315e-6 6.4849e-6 0.00001 1.3846e-9 8.8255e-7 (P5.13.1) N/A 8.8818e-16 0 8.8818e-16 5.12 Surface Area of Revolutionary 3-D (Cubic) Object The upper/lower surface area of a 3-D structure formed by one revolution of a graph (curve) of a function y = f(x) around the x-axis over the interval [a, b] can be described by the following integral: I = 2π b a ydl= 2π b a f(x) 1 +(f (x)) 2 dx (P5.12.1) For example, the surface area of a sphere with the radius of unit length can be obtained from this equation with y = f(x) = 1 −x 2 ,a=−1,b= 1 (P5.12.2) Starting from the program “ nm5p11.m”, make a program “nm5p12.m”that uses the numerical integration routines “ smpsns()” (with the number of segments N = 1000), “adapt_smpsn()”, “quad()”, “quadl()” (with the error tolerance tol=10 −6 )and“Gauss_Legendre()” (with the number of grid points M=20) to evaluate the integral (P5.12.1,2) with the first derivative approximated by Eq. (5.1.8), where the parameters like the num- ber of segments ( N), the error tolerance (tol), and the number of grid points ( M) are supposed to be as they are in the program. Run the program with the step size h = 0.001, 0.0001, and 0.00001 in the numerical derivative and fill in Ta ble P5.11 with the errors of the results, noting that the true value of the surface area of a unit sphere is 4π . 5.13 Volume of Revolutionary 3-D (Cubic) Object The volume of a 3-D structure formed by one revolution of a graph (curve) of a function y = f(x) around the x-axis over the interval [a,b]canbe described by the following integral: I = π b a f 2 (x) dx (P5.13.1) PROBLEMS 259 For example, the volume of a sphere with the radius of unit length (Fig. P5.13) can be obtained from this equation with Eq. (P5.12.2). Starting from the program “ nm5p11.m”, make a program “nm5p13.m” that uses the numer- ical integration routines “ smpsns()” (with the number of segments N= 100 ), “ adapt_smpsn()”, “quad()”, “quadl()” (with the error tolerance tol=10 −6 ), and “Gauss_Legendre()” (with the number of grid points M=2) to evaluate the integral (P5.13.1). Run the program and fill in Table P5.11 with the errors of the results, noting that the volume of a unit sphere is 4π/3. −1 −0.5 −1 0 1 0.5 1 Figure P5.13 The surface and the volume of a unit sphere. 5.14 Double Integral (a) Consider the following double integral I = 2 0 π 0 y sin xdxdy = 2 0 −y cos x π 0 dy = 2 0 2ydy = y 2 2 0 = 4 (P5.14.1) Use the routine “ int2s()” (Section 5.10) with M=N=20, M=N= 50 and M=N=100and the MATLAB built-in routine “dblquad()” to compute this double integral. Fill in Table P5.14.1 with the results and the times measured by using the commands tic/toc to be taken for carrying out each computation. Based on the results listed in Ta ble P5.14.1, can we say that the numerical error becomes smaller as we increase the numbers ( M,N) of segments along the x-axis and y-axis for the routine “ int2s()”? [...]... −1 0 s +1 φ(t) = L−1 {[sI − A]−1 } = L−1 −1 (6. 5.9) = 1 1 − e−t 0 e−t (6. 5.20a) Ad Bd (6. 5.17a) = φ(T ) (6. 5.20a) = −T 1 1−e 0 e−T (6. 5.20b) T (6. 5.17b) = φ(τ ) dτ B 0 T (6. 5.20a) = 0 1 1 − e−τ 0 e−τ T − 1 + e−T 0 = 1 1 − e−T dτ x[n + 1] (6. 5. 16) 1 1 − e−T x1 [n + 1] = x2 [n + 1] 0 e−T = (6. 5.20c) Ad x[n] + Bd u[n] T − 1 + e−T x1 [n] + x2 [n] 1 − e−T u[n] (6. 5.21) We don’t need any special algorithm... %Eq. (6. 1.3): plot([k - 1 k]*h,[y(k) y(k+1)],’b’, k*h,y(k+1),’ro’) if k < 4, pause; end end end and the numerical solution (6. 1.4) with the step-size h = 0.5 and h = 0.25 are as listed in Table 6. 1 and depicted in Fig 6. 1 We make a MATLAB program “nm610.m”, which uses Euler’s method for the differential equation (6. 1.1), actually solving the difference equation (6. 1.3) and plots the graphs of the numerical. .. modifiers Figure 6. 3 1.5 true analytical solution y (t ) = and numerical solutions et 1 −1 0 2 4 6 8 10 (a1) Numerical solutions without modifiers × 104 0 × 10–4 0 2 true analytical solution y (t ) = e t − 1 and numerical solutions 6 8 10 × 10–4 RK4 ABM Hamming 1 1 4 (b1) Relative errors without modifiers 1.5 2 0.5 0 0 2 4 6 8 10 (a2) Numerical solutions with modifiers × 104 3 0 2 1 0 2 4 6 8 (a3) Numerical. .. s+1 X1 (s) = (6. 5.11) (6. 5.12a) (6. 5.12b) which conforms with Eq (6. 5.10) The MATLAB program “nm651_2.m” uses a symbolic computation routine “ilaplace()” to get the inverse Laplace transform, uses “eval()” to evaluate 280 ORDINARY DIFFERENTIAL EQUATIONS 1.5 1 x 1(t ) 0.5 x 2(t ) 0 −0.5 −1 0 0.5 1 1.5 2 Figure 6. 5 Numerical/ analytical solutions of the continuous-time state equation (6. 5.2)/ (6. 5.3) it,... tf 6. 1 EULER’S METHOD When talking about the numerical solutions to ODEs, everyone starts with the Euler’s method, since it is easy to understand and simple to program Even though its low accuracy keeps it from being widely used for solving ODEs, it gives us a Applied Numerical Methods Using MATLAB , by Yang, Cao, Chung, and Morris Copyright 2005 John Wiley & Sons, Inc., ISBN 0-471 -69 833-4 263 264 ... illustrated in Fig 6. 4, which 275 PREDICTOR–CORRECTOR METHOD 6 1 × 10−5 4 0.5 true analytical solution y (t ) = 1 − e−t and numerical solutions 0 2 0 2 4 6 8 10 (a1) Numerical solutions without modifiers 0 1.5 1 0 2 4 6 8 10 (b1) Relative errors without modifiers × 10−5 RK4 ABM Hamming 1 0.5 true analytical solution y (t ) = 1 − e−t and numerical solutions 0 0 0.5 2 4 6 8 10 (a2) Numerical solutions... we look into several methods of obtaining the numerical solutions to ordinary differential equations (ODEs) in which all dependent variables (x) depend on a single independent variable (t) First, the initial value problems (IVPs) will be handled with several methods including Runge–Kutta method and predictor–corrector methods in Sections 6. 1 to 6. 5 The final section (Section 6. 6) will introduce the... (6. 5.7) VECTOR DIFFERENTIAL EQUATIONS 279 we can take the inverse Laplace transform of Eq (6. 5.5) to write t x(t) = φ(t)x(0) + φ(t) ∗ Bu(t) = φ(t)x(0) + φ(t − τ )Bu(τ ) dτ (6. 5.8) 0 For Eq (6. 5.3), we use Eq (6. 5 .6) to find φ(t) = L−1 {[sI − A]−1 } = L−1 = L−1 −1 0 1 s 0 − 0 −1 0 s = L−1 1 s+1 0 s(s + 1) 1/s 0 = L−1 s −1 0 s+1 −1 1 s 1/s − 1/(s + 1) 1/(s + 1) = 1 0 1 − e−t e−t (6. 5.9) and use Eqs (6. 5.8),... a truncation error of O(h4 ) is one of the most widely used methods for solving differential equations Its algorithm is described below yk+1 = yk + h (fk1 + 2fk2 + 2fk3 + fk4 ) 6 (6. 3.1) where fk1 = f(tk , yk ) (6. 3.2a) fk2 = f(tk + h/2, yk + fk1 h/2) (6. 3.2b) fk3 = f(tk + h/2, yk + fk2 h/2) (6. 3.2c) fk4 = f(tk + h, yk + fk3 h) (6. 3.2d) 268 ORDINARY DIFFERENTIAL EQUATIONS function [t,y] = ode_RK4(f,tspan,y0,N,varargin)... {y(kh)}, which we call a numerical solution of Eq (6. 1.1) To be specific, let the parameters and the initial value of Eq (6. 1.1) be a = 1, r = 1, and y0 = 0 Then, the analytical solution (6. 1.2) becomes y(t) = 1 − e−at (6. 1.5) 265 EULER’S METHOD %nm610: Euler method to solve a 1st-order differential equation clear, clf a = 1; r = 1; y0 = 0; tf = 2; t = [0:0.01:tf]; yt = 1 - exp(-a*t); %Eq. (6. 1.5): true analytical . solving ODEs, it gives us a Applied Numerical Methods Using MATLAB , by Yang, Cao, Chung, and Morris Copyr ight 2005 John Wiley & Sons, I nc., ISBN 0-471 -69 833-4 263 264 ORDINARY DIFFERENTIAL. Gauss (P5.11.1,2) 0.001 4 .62 12e-2 2.9822e-2 8.4103e-2 0.0001 9.4278e-3 9.4277e-3 0.00001 2.1853e-1 2.9858e-3 8.4937e-2 (P5.12.1,2) 0.001 1.2393e-5 1.3545e-5 0.0001 8. 362 6e-3 5.0315e -6 6.4849e -6 0.00001 1.3846e-9. Integrals Simpson adaptive quad Gauss S&S a&a q&q (P5 .6. 1) 8.5740e-3 1.9135e-1 1.1 969 e+0 2.4830e-1 (P5 .6. 2) 6. 6730e -6 0.0000e+0 3.3546e-5 (b) To apply the routines like “smpsns()”, “adapt_smpsn()”,