Math 210, Spring 2013 Assignment #4, part B solutions
Math 210, Spring 2013 Assignment #4, part B solutions
Math 210, Spring 2013 Assignment #4, part B solutions
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
<strong>Math</strong> <strong>210</strong>, <strong>Spring</strong> <strong>2013</strong><br />
<strong>Assignment</strong> <strong>#4</strong>, <strong>part</strong> B <strong>solutions</strong><br />
O restart;<br />
Q#1<br />
Specify the differential equation and initial conditions<br />
O de d diff u t , t = sin u t ;<br />
de := d<br />
u t = sin u t<br />
dt<br />
O<br />
O<br />
O<br />
O<br />
ic d u 0 = 1;<br />
dsolve de, ic , u t ;<br />
u t = arctan<br />
ic := u 0 = 1<br />
2 e t sin 1 K1 C cos 1<br />
Ksin 1 2 K 2 e t 2 C 2 e t 2 cos 1 C e t 2 sin 1<br />
K 2 et 2 cos 1 C sin 1 2 C e t 2 sin 1 2 t 2<br />
K 2 e<br />
Ksin 1 2 K 2 e t 2 C 2 e t 2 cos 1 C e t 2 sin 1 2<br />
soln d rhs % ;<br />
soln := arctan<br />
2 e t sin 1 K1 C cos 1<br />
Ksin 1 2 K 2 e t 2 C 2 e t 2 cos 1 C e t 2 sin 1<br />
K 2 et 2 cos 1 C sin 1 2 C e t 2 sin 1 2 t 2<br />
K 2 e<br />
Ksin 1 2 K 2 e t 2 C 2 e t 2 cos 1 C e t 2 sin 1 2<br />
plot soln, t =K10 ..10 ;<br />
2 ,<br />
2 ,<br />
(1)<br />
(2)<br />
(3)<br />
(4)
Save the value of the exact solution at time 1 for comparison in the next question<br />
O exact d eval soln, t = 1 ;<br />
2 e sin 1 K1 C cos 1<br />
exact := Karctan<br />
2 e 2 cos 1 C sin 1 2 C e 2 sin 1 2 K 2 e 2<br />
Q#2<br />
O dsolve de, ic , u t , numeric ;<br />
proc x_rkf45 ... end proc<br />
O<br />
O<br />
O<br />
O<br />
% 1<br />
% 2<br />
rhs %<br />
3<br />
2<br />
1<br />
K10 K5 0 5<br />
t<br />
10<br />
% K evalf exact<br />
t = 1., u t = 1.95629507388886<br />
u t = 1.95629507388886<br />
1.95629507388886<br />
1.03888862623691 10 -7<br />
Let's set a small value for the options, "abserr" and "relerr" to make this error smaller.<br />
C p<br />
(5)<br />
(6)<br />
(7)<br />
(8)<br />
(9)<br />
(10)
I found I also needed to increase the number of digits used in floating point calculations to obtain the<br />
desired accuracy<br />
O Digits d 20;<br />
Digits := 20<br />
O<br />
O<br />
O<br />
Q#3<br />
Note that the output is supressed by default by putting a : after the "end do" statements, but that output is<br />
forced by the "print" statement.<br />
O for n from 2 to 6 do<br />
u d 1;<br />
N d 2 n ;<br />
k d 1<br />
N ;<br />
eulit d u /evalf u C k$sin u ;<br />
for i from 1 to N do<br />
u d eulit u ;<br />
end do:<br />
errk n d evalf u K exact ;<br />
print N, errk n ;<br />
end do:<br />
4, 0.015831482<br />
O<br />
numsol d dsolve de, ic , u t , numeric, abserr = 1eK12, relerr = 1eK12 ;<br />
numsol := proc x_rkf45 ... end proc<br />
rhs numsol 1 2 K evalf exact<br />
Digits d 10;<br />
8.052033 10 -13<br />
Digits := 10<br />
Following the steps from the posted lesson #6, with an added loop over the N value for the<br />
total number of steps.<br />
8, 0.006737062<br />
16, 0.003078094<br />
32, 0.001467045<br />
64, 0.000715597<br />
(11)<br />
(12)<br />
(13)<br />
(14)<br />
(15)