13.07.2015 Views

Chapter 8 - FET

Chapter 8 - FET

Chapter 8 - FET

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

UNIVERSITY OF JORDANFaculty of Eng. and Tech.Electrical Engineering Dept.Instructor: Ziad R. Al-KhatibIntroduction to MATLAB 7for EngineersWilliam J. Palm III<strong>Chapter</strong> 8Numerical Calculus and Differential EquationsZ.R.KZ.R.K


The area A under the curve of f (x) from x = a to x = b.Figure 8.1–1A =∫ baf(x) dxFind the followingintegral:∫A = sin(x 2 ) dx Fresnel’s cosine integral8-2Z.R.K


Illustration of (a) Rectangular and (b) Trapezoidalnumerical integration. Figure 8.2–18-3Z.R.K


Numerical integration functions. Table 8.2–1DescriptionUses an adaptive Simpson’s rule tocompute the integral of the function’fun’ with a as the lowerCommandquad(’fun’,a,b,tol)quadl(’fun’,a,b,tol)trapz(x,y)8-4Z.R.Kintegration limit and b as the upperlimit. The parameter tol is optional.tol indicates the specified errortolerance.Uses Lobatto quadrature to computethe integral of the function ’fun’.The rest of the syntax is identical toquad.Uses trapezoidal integration tocompute the integral of y withrespect to x, where the array ycontains the function values at thepoints contained in the array x.


8-5MATLAB function quad implements an adaptiveversion of Simpson’s rule, while the quadl function isbased on an adaptive Lobatto integration algorithm.To compute the sine integral, type:>>A = quad(’sin’,0,pi)The answer given by MATLAB is 2, which is correct. Weuse quadl the same way; namely,>> A = quadl(’sin’,0,pi).Integration example: Create the function:function c2 = cosxsq(x)% cosine x squared function Fresnel’s int.c2 = cos(x.^2);Note that you must use array exponentiation ( .^ ).The quad function is called as follows:>>quad(’cosxsq’,0,sqrt(2*pi))The result is 0.6119.Z.R.K


A potential problem with integration.A function having a singularity at x = 1. Figure 8.1–2The plot of y= 1/(x-1)∫ 1/(x-1) dx= ln|x–1|Some integralshave infinitevalues.These arecalled improperintegrals.8-6Z.R.K


Potential problem with integration: a function having asingularity in its slope function. The top graph shows thefunction y = √x. The bottom graph shows the derivative of y.The slope has a singularity at x = 0. Figure 8.2–2The plots ofy = √ x ,anddy/dx = 0.5/√xSome Slope of theintegrandsbecomes infinitevalues.The slopefunction has asingularity.Z.R.K8-7 More? See pages 468, 475, 476.


8-8Although the quad and quadl functions are moreaccurate than trapz, they are restricted to computing theintegrals of functions and cannot be used when theintegrand is specified by a set of points. For such cases,use the trapz function.Using the trapz function. Compute the integralπ∫ sin x dx0First use 10 panels with equal widths of π/10.The script file isx = linspace(0,pi,10);y = sin(x);trapz(x,y)The answer is 1.9797, which gives a relative error of100(2 - 1.9797)/2) = 1%.Z.R.KMore? See pages 471-474.


Numerical differentiation: Illustration of threemethods for estimating the derivative dy/dx. Figure 8.3–18-9Z.R.K


MATLAB provides the diff function to usefor computing derivative estimates.Its syntax is d = diff(x), where x is avector of values, and the result is a vector dcontaining the differences between adjacentelements in x.That is, if x has n elements, d will have n − 1elements, whered = [x(2) − x(1), x(3) − x(2), . . . , x(n) − x(n −1)].For example, if x = [5, 7, 12, -20], thendiff(x) returns the vector [2, 5, -32].8-10Z.R.K


Commandd = diff(x)Numerical differentiation functions. Table 8.3–1DescriptionReturns a vector d containing the differencesbetween adjacent elements in the vector x.b = polyder(p)Returns a vector b containing the coefficientsof the derivative of the polynomial representedby the vector p.b = polyder(p1,p2)[num, den] =polyder(p2,p1)Returns a vector b containing the coefficientsof the polynomial that is the derivative of theproduct of the polynomials represented byp1 and p2.Returns the vectors num and den containingthe coefficients of the numerator anddenominator polynomials of the derivative ofthe quotient p 2 /p 1 , where p1 and p2 arepolynomials.8-11Z.R.K


MATLAB provides the polyder function touse for computing derivative polynomials.Let p 1 = 5x + 2 and p 2 = 10x 2 + 4x -3.The results can be obtained as follows:>> p1 = [5, 2]; p2 = [10, 4, -3];>> dp1 = polyder(p1)>> dp2 = polyder(p2)>> prod = polyder(p1, p2)>> [num, den] = polyder(p2, p1)The results are:dp1 = [5], dp2 = [20, 4],prod = [150, 80, -7], num = [50, 40, 23],and den = [25, 20, 4].8-12Z.R.K


Differential equations: Free and total step response of theequation τdy/dt+y=f(t), where τ=0.1, f(t)=10 & y(0)=2. Figure 8.4–11- The freeresponsesolution is:y(t)=y(0)e -t/τ2- The forcedresponsesolution is:y(t) =M (1 - e -t/τ )The totalsolution are 1+ 2.Z.R.K8-13 More? See pages 483-485.


Numerical Methods for Differential EquationsLet dy/dt = –10y, y(0) = 2. and 0 ≤ t ≤ 0.5.The true solution is y(t) = 2 e -10t .The following script file solves and plots thesolution by using Euler method.r = -10; delta = 0.02; y(1) = 2; % ?!k=0;for time = [delta:delta:0.5] % ?!k = k + 1;y(k+1) = y(k) + r*y(k)*delta;endt = [0:delta:0.5]; % for true solution.y_t = 2*exp(-10*t); % true solution.plot(t,y,’o’,t,y_t),xlabel(‘t’), ...ylabel(‘y’)8-15Z.R.K


Euler method solution for the free response ofdy/dt = –10y, y(0) = 2. Figure 8.5–18-15Z.R.K


Let dy/dt = –10y, y(0) = 2. and 0 ≤ t ≤ 0.5.The true solution is y(t) = 2 e -10t .The following script file solves and plots thesolution by using Modified Euler method.r = -10; delta = 0.02; y(1) = 2; k=0;for time = [delta:delta:0.5] % ?!k = k + 1;x(k+1) = y(k) + r*y(k)*delta;y(k+1) = y(k) + r*y(k)*delta/2 ...+ r*x(k+1);endt = [0:delta:0.5]; % for true solution.y_t = 2*exp(-10*t); % true solution.plot(t,y,’o’,t,y_t),xlabel(‘t’), ...ylabel(y’)Z.R.K8-16 More? See pages 490-492.


Modified Euler solution of dy/dt = –10y, y(0) = 2. Figure 8.5–38-17Z.R.K


The ode solvers.When used to solve the first order Ordinarydifferential equation dy/dt = f (t, y), the basicsyntax is (using ode23 or ode45 as theexample):[t,y] = ode23(’ydot’, [t_span], y0)where ydot is the name of the function filewhose inputs must be t and y and whose outputmust be a column vector representing dy/dt; thatis, f (t, y). The number of rows in this columnvector must equal the order of the equation.Z.R.K8-18 More? See pages 496-499.


Application of an ode solver to find the response of an RCcircuit . Figure 8.5–5The circuit model forzero input voltage v isRC dy/dt + y = v(t)RC=0.1s, v(t)=0 y(0)=2.First solve this for dy/dt:dy/dt = -10yNext define thefollowing function file.Note: that the order of the inputarguments must be t and y. The func. name rccirc.m.function ydot = rccirc(t,y)ydot = -10*y;8-19Z.R.K


The function is called as follows, and the solutionplotted along with the analytical solution y_true.>> [t, y] = ode45(’rccirc’, [0, 0.5], 2);>> y_true = 2*exp(-10*t); % t gen. in ode45>> plot(t,y,’ro’,t,y_true), xlabel...(’Time(s)’),ylabel(’Capacitor Voltage’)Note: that we need not generate the array t toevaluate y_true, because t is generated by theode45 function.The plot is shown on the next slide.8-20Z.R.K


Free response of an RC circuit. Figure 8.5–6Z.R.K8-21 More? See pages 498-500.


An oscillating solution: Numerical solutions of the equationdy/dt = sin t, y (0) = 0. Using ode45 and ode23. Figure 8.5–7Z.R.K8-22 More? See page 501.


Plots of the applied voltage and the capacitor voltage when theapplied voltage is v (t) = 10e –t / 0.3 sin(pt). Figure 8.5–88-23Z.R.K


Plots of the applied voltage and the capacitor voltage when theapplied voltage is u (t) = 10e –t / 0.05 sin(2πt /0.03). Figure 8.5–98-24Z.R.K


Plots of the applied voltage and the capacitor voltage when theapplied voltage is v (t) = 10e –t / 0.3 sin(2πt /0.03). Figure 8.5–10Z.R.K8-25 More? See pages 502-505.


Extension to Higher-Order EquationsTo use the ODE solvers to solve an equation higher thanorder 1, you must first write the equation as a set offirst-order equations.For example,5d 2 y/dt 2 + 7dy/dt + 4y = f (t)Set: x 1 = y, and x 2 = dy/dtdx 1 /dt = x 21 4dx 2 /dt = f (t) -5 5 x 1 - 7 5 x 2This form is sometimes called the Cauchy form orthe state-variable form.Solve: 5d 2 y/dt 2 + 7dy/dt + 4y = sin t8-26Z.R.K


Suppose that f (t) = sin t. Then the required file isfunction xdot = example1(t,x)% Computes derivatives of two equationsxdot(1) = x(2);xdot(2) = (1/5)*(sin(t)-4*x(1)-7*x(2));xdot = [xdot(1); xdot(2)];Note that:xdot(1) represents dx 1 /dt,xdot(2) represents dx 2 /dt,x(1) represents x 1 , and x(2) represents x 2 .Suppose we want to solve (8.6–1) for 0 ≤ t ≤ 6 with theinitial conditions x 1 (0) = 3, x 2 (0) = 9. Then the initialcondition for the vector x is [3, 9]. To use ode45, youtype[t, x] = ode45(’example1’, [0, 6], [3, 9]);Z.R.K8-27 More? See pages 506-507.


Each row in the vector x corresponds to a time returnedin the column vector t. If you type plot(t,x), you willobtain a plot of both x 1 and x 2 versus t.Note that x is a matrix with two columns; the first columncontains the values of x 1 at the various times generatedby the solver. The second column contains the values ofx 2 .Thus to plot only x 1 , type plot(t,x(:,1)).An armature-controlled DC motor. Figure 8.6–58-28Z.R.K


From KVL and Newton’s law:v(t) = Ri + Ldi/dt + K e w, di/dt = - (R/L)i - (Ke/L)w - v(t)/LT = K T i = Idw/dt + cw, dw/dt = (K T /I)i – (c/I)w .Where: L, R & I are the motor’s inductance, resistance and inertia;K T & K e are the torque constant & back emf constant. The aboveequations in matrix form is:8-29di/dtdw/dtdx 1 /dt= =dx 2 /dt-R/L -K e /LK T /I-c/Ix 1x 2+1/L0v(t)For example, R=0.6Ω, L=0002H, K T =0.04N.m/A, K e =0.04V.s/rad, c=0and I=6×10 -5 kg.m2 and the applied voltage is:v(t) =100t 0 ≤ t ≤ 0.110 0.1 ≤ t ≤ 0.4-100(t-0.4)+10 0.4 < t ≤ 0.50 t > 0.5Z.R.K


Voltage input and resulting velocity response of a DCmotor. Figure 8.6–6Z.R.K8-30 More? See pages 515-518.


Commandsys = ss(A, B, C, D)[A, B, C, D] =ssdata(sys)sys =tf(right,left)[right, left] =tfdata(sys)LTI object functions. Table 8.7–1DescriptionCreates an LTI object in state-space form, wherethe matrices A, B, C, and D correspond to those inthe model dx/dt = Ax + Bu, y = Cx + Du.Extracts the matrices A, B, C, and D correspondingto those in the modeldx/dt = Ax + Bu, y = Cx + Du.Creates an LTI object in transfer-function form,where the vector right is the vector ofcoefficients of the right-hand side of the equation,arranged in descending derivative order, andleft is the vector of coefficients of the left-handside of the equation, also arranged in descendingderivative order.Extracts the coefficients on the right- and lefthandsides of the reduced-form model.Z.R.K8-31 More? See pages 518-521.


Basic syntax of the LTI ODE solvers. Table 8.7–2CommandDescriptionimpulse(sys)initial(sys,x0)lsim(sys,u,t)step(sys)Computes and plots the unit-impulseresponse of the LTI object sys.Computes and plots the free responseof the LTI object sys given in statemodelform, for the initial conditionsspecified in the vector x0.Computes and plots the response ofthe LTI object sys to the inputspecified by the vector u, at the timesspecified by the vector t.Computes and plots the unit-stepresponse of the LTI object sys.Z.R.K8-32 More? See pages 521-526.


Free response of the model given by (8.7–2) through (8.7–5) for x 1 (0) = 5 and x 2 (0) = -2. Figure 8.7–1>>A=[0,1;-2.5,-1.5];>>B=[0;0.5];>>C=[1,0];>>D=0;>>>>sy=ss(A,B,C,D);>>>>initial(sy,[5,-2])8-33Z.R.K


Step response of the model given by (8.7–2) through (8.7–5) andthe model (8.7–10), for zero initial conditions. Figure 8.7–25x ’’ + 7x ’ + 5x = 5f ’ + f>>s=tf([5,1],...[5,7,5]);>>>>>>step(sy,s,’--’)8-34Z.R.K


Square-wave response of the modelx’’ + 2x’ + 4x = 4f. Figure 8.7–3x ’’ +2x ’ +4x = 4f>>s1=tf(4,[1,2,4]);>>>>[u,t]=gensig(...‘square’,5,10,0.01);>>>>[y,t]=lsim(s1,u,t);>>>>plot(t,y,t,u)8-35Z.R.K


End of <strong>Chapter</strong> 8?Problems Page 532 - 539 !Solve: 4, 14, 19, 23, 31, 38.www.ju.edu.jo\zkhatibZ.R.J.K Z.R.K

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!