Page 122 -
P. 122

This difference equation will be supplemented in the ODE numerical
                             solver routine with the iterative equations for D(k) and D2(k), as given respec-
                             tively by Eqs. (4.16) and (4.30), and with the initial conditions for the function
                             and its derivative. The first elements for the y, D, and D2 arrays are given by:

                                            y() 1 =  y t( =  ) 0

                                                  dy
                                            D() 1 =
                                                  dt t 0=
                                            D () =  ( / 1   b() 1 D() 1 −  c() 1  y() 1 +  u())
                                                      a())(−
                                              21
                                                                              1
                                                    1
                             Application 1
                             To illustrate the use of the first-order iterator algorithm in solving a second-
                             order ordinary differential equation, let us find, over the interval 0 ≤ t ≤ 16π,
                             the voltage across the capacitance in an RLC circuit, with an ac voltage
                             source. This reduces to solve the following ODE:


                                                      2
                                                     dy    dy
                                                   a    +  b  + cy = sin(ω t)              (4.36)
                                                     dt  2  dt
                             where a = LC, b = RC, c = 1. Choose in some normalized units, a = 1, b = 3,
                             ω = 1, and let y(t = 0) = y′(t = 0) = 0.

                             Solution: Edit and execute the following script M-file:

                                tin=0;
                                tfin=16*pi;
                                t=linspace(tin,tfin,2000);
                                a=1;
                                b=3;
                                c=1;
                                w=1;
                                N=length(t);
                                y=zeros(1,N);
                                dt=(tfin-tin)/(N-1);
                                u=sin(w*t);
                                y(1)=0;
                                D(1)=0;
                                D2(1)=(1/a)*(-b*D(1)-c*y(1)+u(1));

                                   for k=2:N

                             © 2001 by CRC Press LLC
   117   118   119   120   121   122   123   124   125   126   127