LearningGuide

# 72 ordinary dierential equations deplot eq1 eq2 xt

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

This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 630 22680 1247400 [1 − x + > plot( %, x=1..10 ); 3 2 1 0 –1 –2 –3 –4 2 4 x6 8 10 The type=numeric Option Although the series methods for solving ODEs are well understood and adequate for ﬁnding accurate approximations of the dependent variable, they do exhibit some limitations. To obtain a result, the resultant series must converge. Moreover, in the process of ﬁnding the solution, Maple must calculate many derivatives, which can be expensive in terms of time and memory. For these and other reasons, alternative numerical solvers have been developed. Here is a diﬀerential equation and an initial condition. > eq := x(t) * diff(x(t), t) = t^2; eq := x(t) ( d x(t)) = t2 dt 252 • Chapter 7: Solving Calculus Problems > ini := x(1) = 2; ini := x(1) = 2 The output from the dsolve command with the numeric option is a procedure that returns a list of equations. > sol := dsolve( {eq, ini}, {x(t)}, type=numeric ); sol := proc(x _rkf45 ) . . . end proc The solution satisﬁes the initial condition. > sol(1); [t = 1., x(t) = 2.] > sol(0); [t = 0., x(t) = 1.82574790049820024] Use the eval command to select a particular value from the list of equations. > eval( x(t), sol(1) ); 2. You can also create an ordered pair. > eval( [t, x(t)], sol(0) ); [0., 1.82574790049820024] The plots package contains a command, odeplot, for plotting the result of dsolve( ..., type=numeric). > with(plots): 7.2 Ordinary Diﬀerential Equations > odeplot( sol, [t, x(t)], -1..2 ); • 253 2.8 2.6 2.4 x 2.2 2 1.8 –1 –0.5 0 0.5 1 t 1.5 2 For the syntax of odeplot, refer to the ?plots,odeplot help page. Here is a system of two ODEs. > eq1 := diff(x(t),t) = y(t); eq1 := d x(t) = y(t) dt > eq2 := diff(y(t),t) = x(t)+y(t); eq2 := > ini := d y(t) = x(t) + y(t) dt x(0)=2, y(0)=1; ini := x(0) = 2, y(0) = 1 In this case, the solution-procedure yields a list of three equations. > sol1 := dsolve( {eq1, eq2, ini}, {x(t),y(t)}, > type=numeric ); sol1 := proc(x _rkf45 ) . . . end proc > sol1(0); [t = 0., x(t) = 2., y(t) = 1.] 254 • Chapter 7: Solving Calculus Problems > sol1(1); [t = 1., x(t) = 5.58216755967155986, y(t) = 7.82688931187210280] Use the odeplot command to plot y(t) against x(t), > odeplot( sol1, [x(t), y(t)], -3..1, labels=["x","y"] ); 8 6 y4 2 0 –2 –4 2 3 4 x 5 6 x(t) and y(t) against t, > odeplot( sol1, [t, x(t), y(t)], -3..1, > labels=["t","x","y"], axes=boxed ); 8 y –4 2 x 6 1 t –3 or any other combination. Important: Use caution when using numeric methods because errors can accumulate in ﬂoating-point calculations. Universal rules for preventing this eﬀect do not exist; no software package can anticipate all conditions. The solution is to use the startinit option to make dsolve (or rather the procedure which dsolve returns) begin at the initial value for every calculation at a point (x, y (x)). 7.2 Ordinary Diﬀerential Equations • 255 You can specify which algorithm dsolve(..., type=numeric) uses when solving your diﬀer...
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