a As in Example 17.5, the humps function can be integrated with the quad function as in The nonlinear model can be expressed as the following set of ODEs,

218 -10 -5 5 10 15 1 2 3 4 c function yp = dyt,y yp = 5y-t2; tspan = [0,5]; y0 = 0.08; [t,y] = ode45dy1,tspan,y0; d [t,y] = ode23sdy1,tspan,y0; e [t,y] = ode23tbdy1,tspan,y0; -30 -20 -10 10 20 30 1 2 3 4 5 RK4 Analytical ODE45 ODE23s ODE23tb

19.9 a As in Example 17.5, the humps function can be integrated with the quad function as in

format long quadhumps,0,1 ans = 29.85832612842764 b Using ode45 is based on recognizing that the evaluation of the definite integral 219 dx x f I b a ∫ = is equivalent to solving the differential equation x f dx dy = for yb given the initial condition ya = 0. Thus, we must solve the following initial-value problem: 6 04 . 9 . 1 01 . 3 . 1 2 2 − + − + + − = x x dx dy where y0 = 0. To do this with ode45, we must first set up an M-file to evaluate the right- hand side of the differential equation, function dy = humpsODEx,y dy = 1.x-0.3.2 + 0.01 + 1.x-0.9.2+0.04 - 6; Then, the integral can be evaluated as [x,y] = ode45humpsODE,[0 0.5 1],0; disp[x,y] 0 0 0.50000000000000 21.78356481821654 1.00000000000000 29.85525185285369 Thus, the integral estimate is within 0.01 of the estimate obtained with the quad function. Note that a better estimate can be obtained by using the odeset function to set a smaller relative tolerance as in options = odesetRelTol,1e-8; [x,y] = ode45humpsODE,[0 0.5 1],0,options; disp[x,y] 0 0 0.50000000000000 21.78683736423308 1.00000000000000 29.85832514287622

19.10 The nonlinear model can be expressed as the following set of ODEs,

v dt d = θ θ sin l g dt dv − = where v = the angular velocity. A function can be developed to compute the right-hand-side of this pair of ODEs for the case where g = 9.81 and l = 0.6 m, function dy = dpnont, y dy = [y2;-9.810.6siny1]; 220 The linear model can be expressed as the following set of ODEs, v dt d = θ θ l g dt dv − = A function can be developed as, function dy = dplint, y dy = [y2;-9.810.6y1]; Then, the solution and plot can be obtained for the case where θ 0 = π 8. Note that we only depict the displacement θ or y1 in the plot [tn yn] = ode45dpnon,[0 10],[pi8 0]; [tl yl] = ode45dplin,[0 10],[pi8 0]; plottn,yn:,1,tl,yl:,1,-- legendnonlinear,linear You should notice two aspects of this plot. First, because the displacement is small, the linear solution provides a decent approximation of the more physically realistic nonlinear case. Second, the two solutions diverge as the computation progresses. For the larger initial displacement θ 0 = π 8, the solution and plot can be obtained as, [tn yn] = ode45dpnon,[0 10],[pi2 0]; [tl yl] = ode45dplin,[0 10],[pi2 0]; plottn,yn:,1,tl,yl:,1,-- legendnonlinear,linear 221 Because the linear approximation is only valid at small displacements, there are now clear and significant discrepancies between the nonlinear and linear cases that are exacerbated as the solution progresses.

19.11 A function can be developed to compute the right-hand-side of the ODE,