Often such external data is in the form of columns of

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ry Differential Equations • 265 The Heaviside Step Function Using the Heaviside function allows you to model delayed and piecewise-defined forcing functions. You can use Heaviside with dsolve to find both symbolic and numeric solutions. > eq := diff(y(t),t) = -y(t)*Heaviside(t-1); eq := d y(t) = −y(t) Heaviside(t − 1) dt > ini := y(0) = 3; ini := y(0) = 3 > dsolve({eq, ini}, {y(t)}); y(t) = 3 e((−t+1) Heaviside(t−1)) Convert the solution to a function that can be plotted. > rhs( % ); 3 e((−t+1) Heaviside(t−1)) > f := unapply(%, t); f := t → 3 e((−t+1) Heaviside(t−1)) > plot(f, 0..4); 3 2.5 2 1.5 1 0.5 0 1 2 3 4 Solve the same equation numerically. 266 • Chapter 7: Solving Calculus Problems > sol1 := dsolve({eq, ini}, {y(t)}, type=numeric); sol1 := proc(x _rkf45 ) . . . end proc Use the odeplot command from the plots package to plot the solution. > with(plots): > odeplot( sol1, [t, y(t)], 0..4 ); 3 2.5 2 y1.5 1 0.5 0 1 2 t 3 4 The Dirac Delta Function You can use the Dirac delta function in a manner similar to the Heaviside function above to produce impulsive forcing functions. > eq := diff(y(t),t) = -y(t)*Dirac(t-1); eq := > ini := y(0) = 3; d y(t) = −y(t) Dirac(t − 1) dt ini := y(0) = 3 > dsolve({eq, ini}, {y(t)}); y(t) = 3 e(−Heaviside(t−1)) Convert the solution to a function that can be plotted. 7.2 Ordinary Differential Equations > f := unapply( rhs( % ), t ); • 267 f := t → 3 e(−Heaviside(t−1)) > plot( f, 0..4 ); 3 2.8 2.6 2.4 2.2 2 1.8 1.6 1.4 1.2 0 1 2 3 4 However, the numeric solution does not see the nonzero value of Dirac(0). > sol2 := dsolve({eq, ini}, {y(t)}, type=numeric); sol2 := proc(x _rkf45 ) . . . end proc Use odeplot from plots to plot the numeric solution. > with(plots, odeplot); [odeplot ] > odeplot( sol2, [t,y(t)], 0..4 ); 268 • Chapter 7: Solving Calculus Problems 4 3.5 y3 2.5 2 0 1 2 t 3 4 Piecewise Functions The piecewise command allows you to construct complicated forcing functions by approximating sections of it with analytic functions, and then taking the approximations together to represent the whole function. First, look at the behavior of piecewise. > f:= x -> piecewise(1<=x and x<2, 1, 0); f := x → piecewise(1 ≤ x and x < 2, 1, 0) > f(x); 1, if , 1 − x ≤ 0 and x − 2 < 0; 0, otherwise. Note that the order of the conditionals is important. The first conditional that returns true causes the function to return a value. > plot(f, 0..3); 1 0.8 0.6 0.4 0.2 0 0.5 1 1.5 2 2.5 3 Thus, you can use this piecewise function as a forcing function. 7.2 Ordinary Differential Equations > eq := diff(y(t),t) = 1-y(t)*f(t); • 269 eq := d y(t) = 1 − y(t) dt 1, if 1 − t ≤ 0 and t − 2 < 0; 0, otherwise. > ini := y(0)=3; ini := y(0) = 3 > sol3 := dsolve({eq, ini}, {y(t)}, type=numeric); sol3 := proc(x _rkf45 ) . . . end proc Use the odeplot command in the plots package to plot the result....
View Full Document

This note was uploaded on 08/27/2012 for the course MATH 1100 taught by Professor Nil during the Spring '12 term at National University of Singapore.

Ask a homework question - tutors are online