0% found this document useful (0 votes)
15 views8 pages

rk4 Complete Ques

Uploaded by

Roy Tufail
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views8 pages

rk4 Complete Ques

Uploaded by

Roy Tufail
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

>

EXERCISE 2.6
Question no 9: Solve DE for stepsize 05, 0.1 and 1 find the value of y(3).

FOR STEPSIZE 0.5


y(3) means to take array values from 0 to 3 with difference of 0.5.
> with plots :
> IVP d diff y t , t = y t $ 15 K 3$y t , y 0 = 2 ;
d
IVP d y t = y t 15 K 3 y t , y 0 = 2 (1)
dt
> Sol d dsolve IVP, y t ;
10
Sol d y t = K15 t
(2)
2C3 e
> RK4 d dsolve IVP, numeric, method = classical rk4 , output = Array 0.0, 0.5, 1.0, 1.5, 2.0,
2.5, 3.0 , stepsize = 0.5
t y t

0. 2.
0.5 K1736.10701847076
50
1.0 K1.24950160714403 # 10
RK4 d (3)
1.5 Float -N
2.0 Float -N
2.5 Float -N
3.0 Float -N

> RK41 d convert RK4 2, 1 , listlist


50
RK41 d 0., 2. , 0.5, K1736.10701847076 , 1.0, K1.24950160714403 # 10 , 1.5, Float (4)
-N , 2.0, Float -N , 2.5, Float -N , 3.0, Float -N
> RK4ptplot d pointplot RK41, symbol = soliddiamond, symbolsize = 14, color = black ;
0
1 2 3
49
K2. # 10
49
K4. # 10
49
K6. # 10
49
K8. # 10
50
K1. # 10
50
K1.2 # 10
> curve d plot rhs Sol , t = 0 ..3, thickness = 3 ;
5
4.5
4

3.5
3
2.5

0 1 2 3
t
> display curve, RK4ptplot ;
0
1 2 3
49 t
K2. # 10
49
K4. # 10
49
K6. # 10
49
K8. # 10
50
K1. # 10
50
K1.2 # 10
> FuncSol d dsolve IVP, numeric, stepsize = 0.5, method = classical rk4 , output
= listprocedure ;
FuncSol d t = proc t ... end proc, y t = proc t ... end proc (5)
> y2 d eval y t , FuncSol
y2 d proc t ... end proc (6)
> seq y2 i , i = 0 ..3
(7)
50
2., K1.24950160714403 # 10 , Float -N , Float -N (7)
10
> actualy2 d t→evalf K15 t
2C3 e
10
actualy2 d t ↦ evalf K15$t
(8)
2 C 3$e
(9)
> seq actualy2 i , i = 0 ..3
2., 4.999997705, 5.000000000, 5.000000000 (10)

> Array t, Numerical_y t , Actual_y t , Percent_Error , seq i, y2 i , evalf actualy2 i ,


y2 i K actualy2 i
evalf 100$abs , i = 0 ..3 ;
actualy2 i
t Numerical_y t Actual_y t Percent_Error
0 2. 2. 0.
50 51
1 K1.24950160714403 # 10 4.999997705 2.49900436133106 # 10 (11)
2 Float -N 5.000000000 Float N
3 Float -N 5.000000000 Float N
FOR STEPSIZE 1
y(3) means to take array values from 0 to 3 with difference of 1.
> with plots :
> IVP d diff y t , t = y t $ 15 K 3$y t , y 0 = 2 ;
d
IVP d y t = y t 15 K 3 y t , y 0 = 2 (12)
dt
> Sol d dsolve IVP, y t ;
10
Sol d y t = K15 t
(13)
2C3 e
> RK4 d dsolve IVP, numeric, method = classical rk4 , output = Array 0.0, 1.0, 2.0, 3.0 ,
stepsize = 1
t y t

0. 2.
RK4 d 8 (14)
1.0 K4.40535355 # 10
141
2.0 K1.17489744602301 # 10
3.0 Float -N

> RK41 d convert RK4 2, 1 , listlist


8 141
RK41 d 0., 2. , 1.0, K4.40535355 # 10 , 2.0, K1.17489744602301 # 10 , 3.0, Float (15)
-N
> RK4ptplot d pointplot RK41, symbol = soliddiamond, symbolsize = 14, color = black ;
0
1 2 3
140
K2. # 10

140
K4. # 10

140
K6. # 10

140
K8. # 10

141
K1. # 10

> curve d plot rhs Sol , t = 0 ..3, thickness = 3 ;


5
4.5
4

3.5
3
2.5

0 1 2 3
t
> display curve, RK4ptplot ;
0
1 2 3
140 t
K2. # 10
140
K4. # 10
140
K6. # 10
140
K8. # 10
141
K1. # 10

> FuncSol d dsolve IVP, numeric, stepsize = 1, method = classical rk4 , output = listprocedure ;
FuncSol d t = proc t ... end proc, y t = proc t ... end proc (16)
> y2 d eval y t , FuncSol
y2 d proc t ... end proc (17)
> seq y2 i , i = 0 ..3
(18)
8 141
2., K4.40535355 # 10 , K1.17489744602301 # 10 , Float -N (18)
10
> actualy2 d t→evalf K15 t
2C3 e
10
actualy2 d t ↦ evalf K15$t
(19)
2 C 3$e
(20)
> seq actualy2 i , i = 0 ..3
2., 4.999997705, 5.000000000, 5.000000000 (21)

> Array t, Numerical_y t , Actual_y t , Percent_Error , seq i, y2 i , evalf actualy2 i ,


y2 i K actualy2 i
evalf 100$abs , i = 0 ..3 ;
actualy2 i
t Numerical_y t Actual_y t Percent_Error
0 2. 2. 0.
8 9
1 K4.40535355 # 10 4.999997705 8.81071124411641 # 10 (22)
141 142
2 K1.17489744602301 # 10 5.000000000 2.34979489204603 # 10
3 Float -N 5.000000000 Float N
>

>

FOR STEPSIZE 0.1


y(3) means to take array values from 0 to 3 with difference of 0.1.

>
> with plots :
> IVP d diff y t , t = y t $ 15 K 3$y t , y 0 = 2 ;
d
IVP d y t = y t 15 K 3 y t , y 0 = 2 (23)
dt
> Sol d dsolve IVP, y t ;
10
Sol d y t = K15 t
(24)
2C3 e
> RK4 d dsolve IVP, numeric, method = classical rk4 , output = Array 0.0, 0.1, 0.2, 0.3, 0.4,
0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0, 2.1, 2.2, 2.3, 2.4, 2.5,
2.6, 2.7, 2.8, 2.9, 3.0 , stepsize = 0.1
t y t

0. 2.
0.1 3.74179198562833
0.2 4.62742202256609
0.3 4.89643285677944
0.4 4.97154632700253
RK4 d (25)
0.5 4.99220927100966
0.6 4.99786893395888
0.7 4.99941722747814
0.8 4.99984064371199
0.9 4.99995642568395
« «
31 # 2 Matrix

> RK41 d convert RK4 2, 1 , listlist


RK41 d 0., 2. , 0.1, 3.74179198562833 , 0.2, 4.62742202256609 , 0.3, (26)
4.89643285677944 , 0.4, 4.97154632700253 , 0.5, 4.99220927100966 , 0.6,
4.99786893395888 , 0.7, 4.99941722747814 , 0.8, 4.99984064371199 , 0.9,
4.99995642568395 , 1.0, 4.99998808512320 , 1.1, 4.99999674202402 , 1.2,
4.99999910914706 , 1.3, 4.99999975640739 , 1.4, 4.99999993339264 , 1.5,
4.99999998178705 , 1.6, 4.99999999501990 , 1.7, 4.99999999863825 , 1.8,
4.99999999962765 , 1.9, 4.99999999989818 , 2.0, 4.99999999997216 , 2.1,
4.99999999999239 , 2.2, 4.99999999999792 , 2.3, 4.99999999999943 , 2.4,
4.99999999999984 , 2.5, 4.99999999999996 , 2.6, 4.99999999999999 , 2.7,
5.00000000000000 , 2.8, 5.00000000000000 , 2.9, 5. , 3.0, 5.
> RK4ptplot d pointplot RK41, symbol = soliddiamond, symbolsize = 14, color = black ;
5

2
0 1 2 3
> curve d plot rhs Sol , t = 0 ..3, thickness = 3 ;
5
4.5
4

3.5
3
2.5

0 1 2 3
t
> display curve, RK4ptplot ;
5

2
0 1 2 3
t
> FuncSol d dsolve IVP, numeric, stepsize = 0.1, method = classical rk4 , output
= listprocedure ;
FuncSol d t = proc t ... end proc, y t = proc t ... end proc (27)
> y2 d eval y t , FuncSol
y2 d proc t ... end proc (28)
> seq y2 i , i = 0 ..30
2., 4.99998808512320, 4.99999999997216, 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., (29)
5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5.
10
> actualy2 d t→evalf K15 t
2C3 e
10
actualy2 d t ↦ evalf K15$t
(30)
2 C 3$e
(31)
> seq actualy2 i , i = 0 ..30
2., 4.999997705, 5.000000000, 5.000000000, 5.000000000, 5.000000000, 5.000000000, (32)
5.000000000, 5.000000000, 5.000000000, 5.000000000, 5.000000000, 5.000000000,
5.000000000, 5.000000000, 5.000000000, 5.000000000, 5.000000000, 5.000000000,
5.000000000, 5.000000000, 5.000000000, 5.000000000, 5.000000000, 5.000000000,
5.000000000, 5.000000000, 5.000000000, 5.000000000, 5.000000000, 5.000000000

> Array t, Numerical_y t , Actual_y t , Percent_Error , seq i, y2 i , evalf actualy2 i ,


y2 i K actualy2 i
evalf 100$abs , i = 0 ..30 ;
actualy2 i
t Numerical_y t Actual_y t Percent_Error
0 2. 2. 0.
1 4.99998808512320 4.999997705 0.000192397624275737
2 4.99999999997216 5.000000000 5.56799051310009 # 10K10
3 5. 5.000000000 0.
4 5. 5.000000000 0.
(33)
5 5. 5.000000000 0.
6 5. 5.000000000 0.
7 5. 5.000000000 0.
8 5. 5.000000000 0.
« « « «
32 # 4 Array

>
>
>

You might also like