0% found this document useful (0 votes)
7 views13 pages

Ex 9

The document discusses Euler's Method for solving differential equations, providing examples with specific equations and initial conditions. It includes step-by-step calculations for various scenarios, ultimately presenting the results for y at specified t values. Additionally, it highlights the limitations of certain methods when dealing with nonlinear equations.

Uploaded by

Ana Parojinog
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)
7 views13 pages

Ex 9

The document discusses Euler's Method for solving differential equations, providing examples with specific equations and initial conditions. It includes step-by-step calculations for various scenarios, ultimately presenting the results for y at specified t values. Additionally, it highlights the limitations of certain methods when dealing with nonlinear equations.

Uploaded by

Ana Parojinog
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/ 13

Euler’s Method

ACTIVITY 9
𝑑𝑦
1. 𝑑𝑡
= 3 − 2𝑡 − 0.5𝑦 𝑦(0) = 1 , ℎ = 0.25 , 𝑦(5) = ?

x y
____ _________

0 1
0.25 1.625
0.5 2.0469
0.75 2.291
1 2.3796
1.25 2.3322
1.5 2.1657
1.75 1.895
2 1.5331
2.25 1.0914
2.5 0.58002
2.75 0.0075153
3 -0.61842
3.25 -1.2911
3.5 -2.0047
3.75 -2.7541
4 -3.5349
4.25 -4.343
4.5 -5.1751 y(5)= -6.8997
4.75 -6.0282
5 -6.8997

Differential Equation:
𝑑𝑦
= 3 − 2𝑡 − 0.5𝑦 𝑦(0) = 1 𝑡 = 5
𝑑𝑡
dt
+ P(t)y = Q(t)
dy
dt
− 0.5y = 3 − 2t
dy
if = e∫ 𝑃(𝑡)𝑑𝑡 = e∫ −0.5 𝑑𝑡 = e−0.5t
dy 𝑑𝑦
[ − 0.5y = 3 − 2t] (𝑒 −0.5𝑡 ) → 𝑒 −0.5𝑡 − 0.5𝑦𝑒 −0.5𝑡 = 3𝑒 −0.5𝑡 − 2𝑡𝑒 −0.5𝑡
dt 𝑑𝑡
𝑑
∫ (𝑦𝑒 −0.5𝑡 )𝑑𝑡 = ∫ 3𝑒 −0.5𝑡 𝑑𝑡 − ∫ 2𝑡𝑒 −0.5𝑡 𝑑𝑡
𝑑𝑡
𝑦𝑒 −0.5𝑡 = −6𝑒 −0.5𝑡 − (−4𝑡𝑒 −0.5𝑡 + ∫ 4𝑒 −0.5𝑡 𝑑𝑡)
𝑦𝑒 −0.5𝑡 = 4𝑡𝑒 −0.5𝑡 + 2𝑒 −0.5𝑡 + 𝑐
𝑦 = 4𝑡 + 2 + 𝑐𝑒 0.5𝑡
𝑦(0) = 1
1 = 4(0) + 2 + 𝑐 → 𝑐 = −1
𝑦(𝑡) = 4𝑡 + 2 − 𝑒 0.5𝑡
@𝑡 = 5
𝑦(5) = 4(5) + 2 − 𝑒 0.5(5) = 𝟗. 𝟖𝟏𝟕𝟓
Euler’s Method

Laplace Transform:
𝑑𝑦
= 3 − 2𝑡 − 0.5𝑦 𝑦(0) = 1 𝑡 = 5
𝑑𝑡
3 2
sY(s) − 1 = − 2 + 0.5Y(s)
s s
3 2
(s − 0.5)Y(s) = − 2 + 1 𝐸𝑡𝑟𝑢𝑒 = 9.8175 + 6.8997 = 16.7172
s s
3 2 𝐸𝑡𝑟𝑢𝑒
− + 1 𝑠 2 + 3𝑠 − 2 𝐸𝑟𝑒𝑙𝑎𝑡𝑖𝑣𝑒 = | | (100) = 170.2796 %
𝑠 𝑠2
Y(s) = = 2 9.8175
𝑠 − 0.5 𝑠 (𝑠 − 0.5)
𝑠 2 + 3𝑠 − 2 𝐴 𝑏 𝐶
2
= + 2+
𝑠 (𝑠 − 0.5) 𝑠 𝑠 𝑠 − 0.5
s 2 + 3s − 2 = A(s 2 )(s − 0.5) + B(s)(s − 0.5) + C(s 2 )
A+C= 1
−0.5A + B = 3
−0.5B = −2
𝐴 = 2 𝐵 = 4 𝐶 = −1
2 4 −1
𝑌(𝑠) = + 2 +
𝑠 𝑠 𝑠 − 0.5
𝑦(𝑡) = 4𝑡 + 2 − 𝑒 0.5𝑡
𝑦(5) = 4(5) + 2 − 𝑒 0.5(5) = 𝟗. 𝟖𝟏𝟕𝟓

2. 𝑦 ′ = 𝑦𝑠𝑖𝑛 𝑡 − 1 𝑦(0) = 2 , ℎ = 0.25 , 𝑦(3) = ?


x y
____ ______

0 2
0.25 1.75
0.5 1.6082
0.75 1.551
1 1.5653
1.25 1.6446
1.5 1.7848
1.75 1.9798
2 2.2169
2.25 2.4708
2.5 2.7014
2.75 2.8556
3 2.8781

y(3)= 2.8781

Differential Equation:
𝑦 ′ = 𝑦𝑠𝑖𝑛 𝑡 − 1 𝑦(0) = 2 𝑡 = 3
𝑦 ′ − 𝑦𝑠𝑖𝑛(𝑡) = −1
if = e∫ 𝑃(𝑡)𝑑𝑡 = e∫ − sin(𝑡)𝑑𝑡 = ecos(t)
𝑑𝑦 𝑑 cos(t)
[ − 𝑦𝑠𝑖𝑛(𝑡) = 1] (ecos(t) ) → (e 𝑦) = −𝑒 cos 𝑡
𝑑𝑡 𝑑𝑡
𝑑
∫ (ecos(t) 𝑦)𝑑𝑡 = ∫ −𝑒 cos 𝑡 𝑑𝑡
𝑑𝑡
Euler’s Method

𝑒 cos 𝑡 𝑦 = ∫ −𝑒 cos 𝑡 𝑑𝑡 + 𝐶
𝐸𝑡𝑟𝑢𝑒 = 4.0674 − 2.8781 = 1.1893
𝑦(0) = 2
0 𝐸𝑡𝑟𝑢𝑒
2𝑒 1 = ∫ −𝑒 cos 𝑡 𝑑𝑡 + 𝐶 → 𝐶 = 2𝑒 𝐸𝑟𝑒𝑙𝑎𝑡𝑖𝑣𝑒 = | | (100) = 29.2398 %
4.0674
0
𝑡
𝑦(𝑡) = (∫ −𝑒 cos 𝑡 𝑑𝑡 + 2𝑒) 𝑒 −cos 𝑡
0
3
𝑦(3) = (∫ −𝑒 cos 𝑡 𝑑𝑡 + 2𝑒) 𝑒 −cos 3 = 𝟒. 𝟎𝟔𝟕𝟒
0

𝑥−4
3. 𝑦 ′ = 𝑥−𝑦+1 𝑦(3) = 3 , ℎ = 0.25 , 𝑦(8) = ?

x y
____ ______

3 3
3.25 2.75
3.5 2.625
3.75 2.5583
4 2.5298
4.25 2.5298
4.5 2.5528
4.75 2.5952
5 2.6546
5.25 2.7294
5.5 2.8181
5.75 2.92
6 3.0342
6.25 3.1603
6.5 3.2978
6.75 3.4466
7 3.6063
7.25 3.777
7.5 3.9587 y(8)= 4.3552
7.75 4.1513
8 4.3552

Differential Equation:
𝑥−4
𝑦′ = 𝑦(3) = 3 𝑥 = 8
𝑥−𝑦+1
(𝑥 − 𝑦 + 1)𝑑𝑦 = (𝑥 − 4)𝑑𝑥
𝑥𝑑𝑦 − 𝑦𝑑𝑦 + 𝑑𝑦 = (𝑥 − 4)𝑑𝑥
𝑥𝑑𝑦 − 𝑦𝑑𝑦 = (𝑥 − 4)𝑑𝑥 − 𝑑𝑦

Cannot be solve because it is nonlinear equation


Euler’s Method

𝑡2
𝑑𝑦
4. 𝑑𝑡
= 𝑒 𝑦2+1 𝑦(−0.82) = 0.97 , 𝑦(1.28) = ?

x y
_____ ______

-0.82 0.97
-0.4 1.5639
0.02 2.0039
0.44 2.4239
0.86 2.8559
1.28 3.3112

y(1.28)= 3.3112

Differential Equation:
𝑡 2
𝑑𝑦
= 𝑒 𝑦2 +1
𝑑𝑡
2 +1
∫ 𝑒𝑦 𝑑𝑦 = ∫ 𝑡 2 𝑑𝑡
2 +1 𝑡3
∫ 𝑒𝑦 𝑑𝑦 = +𝑐
3
2 +1
∫ 𝑒𝑦 𝑑𝑦 → ℎ𝑎𝑠 𝑛𝑜 𝑖𝑛𝑡𝑒𝑔𝑟𝑎𝑙

As for Laplace transform approach its not applicable because the


2 +1
function is nonlinear due to the term 𝑒 𝑦 .

𝑑𝑦 𝑦
5. 𝑑𝑡
=4−𝑡−2 𝑦(0) = 1 , ℎ = 0.25 , 𝑦(4) = ?

x y
____ ______

0 1
0.25 1.875
0.5 2.5781
0.75 3.1309
1 3.552
1.25 3.858
1.5 4.0633
1.75 4.1803
2 4.2203
2.25 4.1928
2.5 4.1062
2.75 3.9679
3 3.7844
3.25 3.5614
3.5 3.3037 y(4)= 2.7013
3.75 3.0157
4 2.7013
Euler’s Method

Differential Equation:
𝑑𝑦 𝑦
= 4−𝑡− 𝑦(0) = 1 𝑡 = 4
𝑑𝑡 2
dy
+ P(t)y = Q(t)
dt
𝑑𝑦 𝑦
+ =4−𝑡
𝑑𝑡 2
1 𝑡
𝑖𝑓 = 𝑒 ∫2𝑑𝑡 = 𝑒 2
𝑑𝑦 𝑦 𝑡 𝑡 𝑑𝑦 𝑦 𝑡 𝑡 𝑡
[ + = 4 − 𝑡] (𝑒 2 ) → 𝑒 2 + 𝑒 2 = 4𝑒 2 − 𝑡𝑒 2
𝑑𝑡 2 𝑑𝑡 2
𝑑 𝑡 𝑡 𝑡
∫ (𝑦𝑒 2 ) = ∫ 4𝑒 2 − ∫ 𝑡𝑒 2
𝑑𝑡
𝑡 𝑡 𝑡 𝑡
𝑦𝑒 2 = 8𝑒 2 − 2𝑡𝑒 2 + 2 ∫ 𝑒 2 𝑑𝑡
𝑡 𝑡 𝑡
𝑦𝑒 2 = 12𝑒 2 − 2𝑡𝑒 2 + 𝑐
𝑡
𝑦 = 12 − 2𝑡 + 𝑐𝑒 −2
𝑦(0) = 1
1 = 12 − 0 + 𝑐 → 𝑐 = −11
𝑡
𝑦(𝑡) = 12 − 2𝑡 − 11𝑒 −2
4
𝑦(4) = 12 − 2(4) − 11𝑒 −2 = 𝟐. 𝟓𝟏𝟏𝟑

Laplace Transform:
𝑑𝑦 𝑦
= 4−𝑡− 𝑦(0) = 1 𝑡 = 4
𝑑𝑡 2
4 1 1
sY(s) − 1 = − 2 − Y(s)
s s 2
1 4 1
Y(s) (s + ) = − 2 + 1
2 s s
4 1
− +1
𝑠 𝑠2
𝑌(𝑠) =
1
𝑠+
2
4 𝐴 𝐵
= + 𝐸𝑡𝑟𝑢𝑒 = 2.5113 − 2.7013 = −0.19
1 𝑠 1
𝑠 (𝑠 + ) (𝑠 + )
2 2 𝐸𝑡𝑟𝑢𝑒
𝐴 = 8 𝐵 = −8 𝐸𝑟𝑒𝑙𝑎𝑡𝑖𝑣𝑒 = | | (100) = 7.5658 %
2.5113
4 8 8
= −
1 1
𝑠 (𝑠 + ) 𝑠 𝑠 (𝑠 + )
2 2
1 𝐶 𝐷 𝐸
= 2+ +
1 𝑠 𝑠 1
𝑠 2 (𝑠 + ) 𝑠+
2 2
𝐶 = 2 𝐷 = −4 𝐸 = 4
1 2 4 4
= 2− +
1 𝑠 𝑠+1
𝑠 2 (𝑠 + ) 𝑠
2 2
8 8 2 4 4 1 1
𝑌(𝑠) = − − 2+ − + 𝑦(𝑡) = 12 + 11𝑒 2 − 2𝑡
𝑠 (𝑠 + 1) 𝑠 𝑠 𝑠+1 𝑠+1
4
2 2 2 𝑦(4) = 12 − 2(4) − 11𝑒 −
2 = 𝟐. 𝟓𝟏𝟏𝟑
4 11 2
𝑌(𝑠) = − −
𝑠 𝑠 + 1 𝑠2
2
Euler’s Method

𝑑𝑦
6. 𝑑𝑡
= 1 − 𝑡𝑦 𝑦(0) = 1 , ℎ = 0.25 , 𝑦(6) =?

x y
____ _______

0 1
0.25 1.25
0.5 1.4219
0.75 1.4941
1 1.464
1.25 1.348
1.5 1.1767
1.75 0.98547
2 0.80432
2.25 0.65216
2.5 0.53532
2.75 0.45075
3 0.39086
3.25 0.34771
3.5 0.3152
3.75 0.2894
4 0.26809
4.25 0.25 y(6)= 0.1715
4.5 0.23438
4.75 0.2207
5 0.20862
5.25 0.19785
5.5 0.18817
5.75 0.17944
6 0.1715

Differential Equation:
𝑑𝑦
= 1 − 𝑡𝑦 𝑦(0) = 1 𝑡 = 6
𝑑𝑡
𝑑𝑦
+ 𝑡𝑦 = 1
𝑑𝑡 2 𝑡
𝑖𝑓 = 𝑒 ∫ 𝑡𝑑𝑡 = 𝑒 2
𝑑𝑦 𝑡2 𝑡 2 𝑑𝑦 𝑡2 𝑡2
[ + 𝑡𝑦 = 1] (𝑒 2 ) → 𝑒 2 + 𝑒 2 𝑡𝑦 = 𝑒 2
𝑑𝑡 𝑑𝑡
2 2
𝑑 𝑡 𝑡
∫ (𝑒 2 𝑦) = ∫ 𝑒 2 𝑑𝑡
𝑑𝑡
𝑡2 𝑡2
𝐸𝑡𝑟𝑢𝑒 = 1.17175 − 0.1715 = 1.00025
𝑒 2 𝑦 = ∫ 𝑒 2 𝑑𝑡 + 𝐶
𝑦(0) = 1 𝐸𝑡𝑟𝑢𝑒
0 𝑡2
𝐸𝑟𝑒𝑙𝑎𝑡𝑖𝑣𝑒 = | | (100) = 85.36377 %
0
1.17175
𝑒 = ∫ 𝑒2 +𝐶 → 𝑐 = 1
0
𝑡2 𝑡 𝑡2
𝑦(𝑡) = 𝑒 − 2 ∫ 𝑒 2 𝑑𝑡 + 1
0
𝑡2 6 𝑡2
𝑦(6) = 𝑒− 2 ∫ 𝑒 2 𝑑𝑡 + 1 = 𝟏. 𝟏𝟕𝟏𝟕𝟓
0
Euler’s Method

𝑑𝑦
7. 𝑑𝑥
= −2𝑥 3 + 12𝑥 2 − 20𝑥 + 8.5 𝑦(0) = 1 , ℎ = 0.5 , 𝑦(8) = ?

x y
___ _______

0 1
0.5 5.25
1 5.875
1.5 5.125
2 4.5
2.5 4.75
3 5.875
3.5 7.125
4 7
4.5 3.25
5 -7.125
5.5 -27.875
6 -63.5
6.5 -119.25
7 -201.12 y(8)= -471
7.5 -315.88
8 -471

Differential Equation:
𝑑𝑦
= −2𝑥 3 + 12𝑥 2 − 20𝑥 + 8.5 𝑦(0) = 1 𝑥 = 8
𝑑𝑥
3 2
𝑑𝑦 = (−2𝑥 + 12𝑥 − 20𝑥 + 8.5 )𝑑𝑥
∫ 𝑑𝑦 = ∫(−2𝑥 3 + 12𝑥 2 − 20𝑥 + 8.5 )𝑑𝑥
1
𝑦 = − 𝑥 4 + 4𝑥 3 − 10𝑥 2 + 8.5𝑥 + 𝐶
2
𝑦(0) = 1
1 = −0 + 0 − 0 + 0 + 𝐶 → 𝐶 = 1
1
𝑦(𝑥) = − 𝑥 4 + 4𝑥 3 − 10𝑥 2 + 8.5𝑥 + 1
2
1
𝑦(8) = − (8)4 + 4(8)3 − 10(8)2 + 8.5(8) + 1 = −𝟓𝟕𝟏
2

Laplace Transform:
𝑑𝑦
= −2𝑥 3 + 12𝑥 2 − 20𝑥 + 8.5 𝑦(0) = 1
𝑑𝑥
12 24 20 8.5
𝑠 𝑌(𝑠) − 1 = − 4 + 3 − 2 + 𝐸𝑡𝑟𝑢𝑒 = −571 + 471 = −100
𝑠 𝑠 𝑠 𝑠
1 12 24 20 8.5 𝐸𝑡𝑟𝑢𝑒
𝑌(𝑠) = − 5 + 4 − 3 + 2 𝐸𝑟𝑒𝑙𝑎𝑡𝑖𝑣𝑒 = | | (100) = 17.5131 %
𝑠 𝑠 𝑠 𝑠 𝑠 571
1
𝑦(𝑥) = 1 − 𝑥 4 + 4𝑥 3 − 10𝑥 2 + 8.5𝑥
2
1
𝑦(8) = 1 − (8)4 + 4(8)3 − 10(8)2 + 8.5(8) = −𝟓𝟕𝟏
2
Euler’s Method

𝑑𝑦
8. 𝑑𝑡
= 𝑦𝑡 3 − 1.5𝑦 𝑦(0) = 1 , ℎ = 0.25 & 0.5 , 𝑦(2) =?

Results: h = 0.25
x y
____ _______

0 1
0.25 0.625
0.5 0.39307
0.75 0.25795
1 0.18842
1.25 0.16487
1.5 0.18355
1.75 0.26959
2 0.52969

y(2)= 0.52969 @h=0.25

Results: h = 0.5
x y
___ ________

0 1
0.5 0.25
1 0.078125
1.5 0.058594
2 0.11353

y(2)= 0.11353 @h=0.5

Differential Equation:
𝑑𝑦
= 𝑦𝑡 3 − 1.5𝑦 , 𝑦(0) = 1 , 𝑡 = 2
𝑑𝑡

𝑑𝑦 𝑑𝑡 𝑑𝑦
[ = 𝑦𝑡 3 − 1.5𝑦] ( ) → = (𝑡 3 − 1.5)𝑑𝑡
𝑑𝑡 𝑦 𝑦

𝑑𝑦 𝑡4
∫ = ∫ 𝑡 3 𝑑𝑡 − ∫ 1.5𝑑𝑡 → ln 𝑦 = − 1.5𝑡 + 𝑐
𝑦 4

𝑦(0) = 1 𝐸𝑡𝑟𝑢𝑒 ℎ=0.25 = 2.7183 − 0.52969 = 2.18861


04
ln 1 = − 1.5(0) + 𝑐 → 𝑐 = 0 𝐸𝑡𝑟𝑢𝑒
4 𝐸𝑟𝑒𝑙𝑎𝑡𝑖𝑣𝑒 ℎ=0.25 = | | (100) = 80.5139 %
2.7183
𝑡4 𝑡4
𝑒 ln 𝑦 = 𝑒 4 −1.5𝑡 → 𝑦 = 𝑒 4 −1.5𝑡 𝐸𝑡𝑟𝑢𝑒 ℎ=0.5 = 2.7183 − 0.11353 = 2.60477
𝑡=2 𝐸𝑡𝑟𝑢𝑒
𝐸𝑟𝑒𝑙𝑎𝑡𝑖𝑣𝑒 ℎ=0.5 = | | (100) = 95.8235 %
24 2.7183
𝑦 = 𝑒 4 −1.5(2) = 𝟐. 𝟕𝟏𝟖𝟑
Euler’s Method

𝑑𝑦 1+2𝑥
9. 𝑑𝑥
= 𝑦(0) = 1 , ℎ = 0.25 & 0.5
√𝑦

Results: h = 0.25
x y
____ ______

0 1
0.25 1.25
0.5 1.5854
0.75 1.9825
1 2.4264
1.25 2.9079
1.5 3.421
1.75 3.9617
2 4.5269
2.25 5.1144
2.5 5.7224
2.75 6.3494 y(3)= 6.9943 @h=0.25
3 6.9943

Results: h = 0.5
x y
___ ______

0 1
0.5 1.5
1 2.3165
1.5 3.302
2 4.4027
2.5 5.5941
3 6.8625
y(3)= 6.8625 @h=0.5

Differential Equation:
𝑑𝑦 1 + 2𝑥
= 𝑦(0) = 1 𝑥 = 3
𝑑𝑥 √𝑦
√𝑦𝑑𝑦 = (1 + 2𝑥)𝑑𝑥
1 𝐸𝑡𝑟𝑢𝑒 ℎ=0.25 = 7.1204 − 6.9943 = 0.1261
∫ 𝑥 2 𝑑𝑦 = ∫ 𝑑𝑥 + 2 ∫ 𝑥𝑑𝑥
𝐸𝑡𝑟𝑢𝑒
2 3 𝐸𝑟𝑒𝑙𝑎𝑡𝑖𝑣𝑒 ℎ=0.25 = | | (100) = 1.771 %
𝑦2 = 𝑥 + 𝑥2 + 𝐶 7.1204
3
𝑦(0) = 1 𝐸𝑡𝑟𝑢𝑒 ℎ=0.5 = 7.1204 − 6.8625 = 0.2579
2 3 2
(1)2 = 0 + 0 + 𝐶 → 𝐶 = 𝐸𝑡𝑟𝑢𝑒
3 3 𝐸𝑟𝑒𝑙𝑎𝑡𝑖𝑣𝑒 ℎ=0.5 = | | (100) = 3.622 %
2 7.1204
3 3 3
𝑦(𝑥) = ( 𝑥 + 𝑥 2 + 1)
2 2
2
3 3 3
𝑦(3) = ( (3) + (3)2 + 1) = 𝟕. 𝟏𝟐𝟎𝟒
2 2
Euler’s Method

𝑑2 𝑦 𝑑𝑦
10. 𝑑𝑥 2
+ 0.5 𝑑𝑥 + 7𝑦 = 0 𝑦(0) = 4 , 𝑦 ′ (0) = 0 , ℎ = 0.5

x y dy_dx
___ _______ _______

0 4 0
0.5 4 -14
1 -3 -24.5
1.5 -15.25 -7.875
2 -19.188 47.469
2.5 4.5469 102.76
3 55.926 61.154
3.5 86.503 -149.87
4 11.566 -415.17
4.5 -196.02 -351.85
5 -371.94 422.17

y(5)= -371.94

Differential Equation:
𝑑2 𝑦 𝑑𝑦
+ 0.5 + 7𝑦 = 0 𝑦(0) = 4 𝑦 ′ (0) = 0 𝑥 = 5
𝑑𝑥 2 𝑑𝑥
𝑚2 𝑦 + 0.5𝑚𝑦 + 7𝑦 = 0 𝑦=0
1 √111
𝑚=− ± 𝑖
4 4
𝑦(𝑥) = 𝑒 𝛼𝑥 (𝐶1 𝑐𝑜𝑠(𝛽𝑥) + 𝐶2 𝑠𝑖𝑛(𝛽𝑥))
𝑦(𝑥) = 𝑒 −0.25𝑥 (𝐶1 𝑐𝑜𝑠(2.63𝑥) + 𝐶2 𝑠𝑖𝑛(2.63𝑥))
𝑦(0) = 4
4 = 𝑒 −0.25(0) (0)(𝐶1 𝑐𝑜𝑠(2.63 ⋅ 0) + 𝐶2 𝑠𝑖𝑛(2.63 ⋅ 0))
4 = 1(𝐶1 + 𝐶2 (0)) → 𝐶 = 4
𝑑 −0.25𝑥
𝑦 ′ (𝑥) = [𝑒 (𝐶1 𝑐𝑜𝑠(2.63𝑥) + 𝐶2 𝑠𝑖𝑛(2.63𝑥))]
𝑑𝑥
𝑦′(𝑥) = −0.25𝑒 −0.25𝑥 (𝐶1 𝑐𝑜𝑠(2.63𝑥) + 𝐶2 𝑠𝑖𝑛(2.63𝑥)) + 𝑒 −0.25𝑥 (−2.63𝐶1 𝑠𝑖𝑛(2.63𝑥)
+ 2.63𝐶2 𝑐𝑜𝑠(2.63𝑥))
𝑦 ′ (0) = 0
0 = −0.25𝑒 0 (𝐶1 𝑐𝑜𝑠(0) + 𝐶2 𝑠𝑖𝑛(0)) + 𝑒 0 (−2.63𝐶1 𝑠𝑖𝑛(0) + 2.63𝐶2 𝑐𝑜𝑠(0))
0 = −0.25(4 + 0) + 1(0 + 2.63𝐶2 ) → 𝐶2 = 0.38
𝑦(𝑥) = 𝑒 −0.25𝑥 (4𝑐𝑜𝑠(2.63𝑥) + 0.38𝑠𝑖𝑛(2.63𝑥))
𝑦(5) = 𝑒 −0.25(5) (4 cos(2.63(5)) + 0.38 sin(2.63(5)) = 𝟏. 𝟎𝟏𝟔𝟑

Laplace Transform:
𝑑2 𝑦 𝑑𝑦
2
+ 0.5 + 7𝑦 = 0 𝑦(0) = 4 𝑦 ′ (0) = 0
𝑑𝑥 𝑑𝑥
𝑠 2 𝑌(𝑠) − 𝑠 𝑦(0) − 𝑦 ′ (0) + 0.5(𝑠𝑌(𝑠) − 𝑦(0)) + 7𝑌(𝑠) = 0
𝑠 2 𝑌(𝑠) + 0.5𝑠𝑌(𝑠) + 7𝑌(𝑠) = 6
6 6 6
𝑌(𝑠) = 2 → 𝑌(𝑠) = → 𝑌(𝑠) =
𝑠 + 0.5𝑠 + 7 0.5 2 0.5 2 (𝑠 + 0.25)2 + (6.937)
(𝑠 + ) +7−( )
2 2
6
𝑌(𝑠) = → 𝑦(𝑥) = 6𝑒 −0.25𝑥 sin(2.6339𝑥)
(𝑠 + 0.25)2 + (2.6339)2
𝑦(5) = 6𝑒 −0.25(5) sin(2.6339(5)) = 𝟎. 𝟑𝟗𝟏𝟕
Euler’s Method

Euler’s Method Code:

disp('You can choose to solve a 1st or 2nd order differential equation.');

order = input('Enter the order of the differential equation (1 or 2): ');

if order == 1

f_str = input('Enter the function f(x, y) as a string (e.g., "x + y"): ',
's');
f = str2func(['@(x, y) ' f_str]);

x0 = input('Enter the initial value of x (x0): ');


y0 = input('Enter the initial value of y (y0): ');
h = input('Enter the step size (h): ');
x_end = input('Enter the end value of x: ');

x = x0;
y = y0;
x_values = x0:h:x_end;
y_values = zeros(size(x_values));
y_values(1) = y0;

for i = 2:length(x_values)
y = y + h * f(x, y);
x = x + h;
y_values(i) = y;
end

disp('Results:');
disp(table(x_values', y_values', 'VariableNames', {'x', 'y'}));

figure;
plot(x_values, y_values, '-o', 'LineWidth', 1.5);
grid on;
title('Euler''s Method Solution for 1st Order ODE');
xlabel('x');
ylabel('y');
legend('Numerical Solution');

elseif order == 2

f_str = input('Enter the function f(x, y, dy/dx) as a string (e.g., "-2*dy -


3*y"): ', 's');
Euler’s Method

f = str2func(['@(x, y, dy) ' f_str]);


x0 = input('Enter the initial value of x (x0): ');
y0 = input('Enter the initial value of y (y0): ');
dy0 = input('Enter the initial value of dy/dx (dy0): ');
h = input('Enter the step size (h): ');
x_end = input('Enter the end value of x: ');

x = x0;
y = y0;
dy = dy0;
x_values = x0:h:x_end;
y_values = zeros(size(x_values));
dy_values = zeros(size(x_values));
y_values(1) = y0;
dy_values(1) = dy0;

for i = 2:length(x_values)
ddy = f(x, y, dy);
y = y + h * dy;
dy = dy + h * ddy;
x = x + h;
y_values(i) = y;
dy_values(i) = dy;
end

disp('Results:');
disp(table(x_values', y_values', dy_values', 'VariableNames', {'x', 'y',
'dy_dx'}));

figure;
plot(x_values, y_values, '-o', 'LineWidth', 1.5);
hold on;
plot(x_values, dy_values, '--s', 'LineWidth', 1.5);
grid on;
title('Euler''s Method Solution for 2nd Order ODE');
xlabel('x');
ylabel('Values');
legend('y (Solution)', 'dy/dx (First Derivative)');
hold off;

else
disp('Invalid input. Please enter 1 or 2 for the order of the ODE.');
end
Euler’s Method

You might also like