Tutorial Prob Ans
Tutorial Prob Ans
(a) Noting that the equation is separable, solve the IVP by hand.
Noting that the equation is separable, solve the IVP by hand.
Separating variables and using the technique of partial fractions, we get
3 3
y= 3x
. The use of the initial condition gives us y = .
1 KCe 1 C2 e3 x
O with DEtools :
O ode d diff y x , x = y x * y x K3 ;
O sol d dsolve ode, y 0 = 1 , y x , type = numeric, method = classical foreuler ;
O sol 0.5 ;
O sol 1 ;
(b) Choose the option in dsolve that invokes Euler's method and
solve the IVP numerically.
O
O sol d dsolve ode, y 0 = 1 , y x , type = numeric, method = classical foreuler , output
= listprocedure
O fy d subs sol, y x ;
O seq fy 1 / 10 * i , i = 0 .. 10 ;
(c) Graph the actual solution (part (a)) and the numerical
solution (part (b)) together.
O with plots :
O odeplot sol, x, y x , 0 ..3 ;
O g1 d plot 3 / 1 C2 * exp 3 * x , x = 0 ..3, color = black :
O g2 d odeplot sol, x, y x , 0 ..3 :
O display g1, g2 ;
O
dx
Consider the IVP = 5 x K6 eKt, x 0 = 1 .
dt
(a) Find the actual solution of this linear equation IVP.
(b) Solve the IVP numerically using the improved Euler method.
(c) Compare values of the actual solution and the numerical solution for t = 1, 2, 2.5, 3, and 4.
(d) Graph the actual solution and the numerical solution together for t in the interval [0, 2.5].
(e) Comment on what you see in parts (c) and (d).
(b)
O ode d diff x t , t = 5 * x t K6 * exp Kt ;
O SOL d dsolve ode, x 0 = 1 , x t , type = numeric, method = classical impoly ;
(c) Let's compare values of our actual solution x(t) = exp(-t)
and our numerical solution SOL:
(c) Let's compare values of our actual solution x(t) = exp(-t) and our numerical solution SOL:
O evalf(exp(-1));
O rhs(SOL(1)[2]);
When t = 1, the values of x(t) and SOL are close. Let's compare them when t = 2:
O evalf(exp(-2));
O rhs(SOL(2)[2]);
O rhs(SOL(2.5)[2]);
When t = 3 and t = 4, we see even greater gaps between the actual and the approximate
solutions:
O evalf(exp(-3));
O rhs(SOL(3)[2]);
O evalf(exp(-4));
O rhs(SOL(4)[2]);
(d) Let's look at the graphs of the actual and the numerical solutions.
O with(plots):
O g1:=plot(exp(-t), t=0..2.5, color=black):
O g2:=odeplot(SOL,[t,x(t)],0..2.5):
O display({g1,g2});
O restart;
d2 2 Cy x 2 y x
O deq2 := y x C =1
dx2 1 Cy x 2
O bc2 := y 0 = 0, y 2 = 3; dsol2 := dsolve deq2, bc2 , numeric, output = listprocedure
O fy := subs dsol2, y x ;
i
O seq fy , i = 0 ..10
10
O dsol3 d dsolve deq2, bc2 , numeric, output = array 0, 0.25, 0.5, 0.75, 1
O