Attribution Non-Commercial (BY-NC)

532 views

Attribution Non-Commercial (BY-NC)

- Numerical Methods
- RK4 Method
- Computer Methods for Solving Dynamic Separation Problems
- MATLAB Course - Part 2
- Chapter 1.1 – 1.8 Quiz
- Equations With Defined Variable
- 1510 _Differential Equations in MATLAB
- UCL Notes on 1st Order PDEs
- 55-157-1-PB.pdf
- Bsc Math Syllabus of Physical Sciences
- vit 4years ece syallabus
- Gate Mathematics
- DIFFRENTIAL EQUATION.pdf
- Ground Water
- Math 2301 s 12016
- CHE3482011915035 (1)
- Analytic Solutions to Algebraic Equations
- pavan doc
- 2009 DE Solutions (Mu).pdf
- 12. Mathematics Jntuk

You are on page 1of 18

College of Engineering

Department of Electrical Engineering

2nd Year Electrical

System Dynamics and Control Components

Under Supervision of Professor Dr. A. A. Wahdan

nd

2 Year Electrical Engineering

Group B

Section : 9

Bench No. : 6

Table of Contents :

I – Differential Equations .................................................... 3

i- Definition ....................................................................... 3

ii- Ordinary Differential Equations ................................... 4

iii- Numerical Ordinary Differential Equations ................ 5

i- Introduction .................................................................... 6

ii- Fourth Order Runge-Kutta Method .............................. 6

iii- Computer-Aided 4th Order Runge-Kutta Method ........ 9

1- The Programming Language Python ...................... 9

2- The Program Code .................................................. 9

3- A Sample Runtime ................................................ 14

Differential Equations ............................................... 15

2

I – Differential Equations :

i- Definition :

unknown function of one or several variables that relates the

values of the function itself and its derivatives of various orders.

Differential equations play a prominent role in engineering,

physics, economics and other disciplines.

modeling the acceleration of a ball falling through the air

(considering only gravity and air resistance). The ball's

acceleration towards the ground is the acceleration due to gravity

minus the deceleration due to air resistance. Gravity is a constant

but air resistance is proportional to the ball's velocity. This means

the ball's acceleration is dependent on its velocity. Because

acceleration is the derivative of velocity, solving this problem

requires a differential equation.

different perspectives, mostly concerned with their solutions,

functions that make the equation hold true. Only the simplest

differential equations admit solutions given by explicit formulas.

Many properties of solutions of a given differential equation may

be determined without finding their exact form. If a self-contained

formula for the solution is not available, the solution may be

numerically approximated using computers. The theory of

dynamical systems puts emphasis on qualitative analysis of

systems described by differential equations, while many

numerical methods have been developed to determine solutions

with a given degree of accuracy.

3

ii- Ordinary Differential Equations :

relation that contains functions of only one independent variable,

and one or more of its derivatives with respect to that variable.

to the differential equation:

..

m x = F t

force F depends upon the position of the particle x(t) at time t, and

thus the unknown function x(t) appears on both sides of the

differential equation, as is indicated in the notation F(x(t)).

including geometry, mechanics, astronomy and population

modeling. Many famous mathematicians have studied differential

equations and contributed to the field, including Newton, Leibniz,

the Bernoulli family, Riccati, Clairaut, d'Alembert and Euler.

differential equations. In the case where the equation is linear, it

can be solved by analytical methods. Unfortunately, most of the

interesting differential equations are non-linear and, with a few

exceptions, cannot be solved exactly. Approximate solutions are

arrived at using computer approximations (see numerical ordinary

differential equations).

4

iii- Numerical Ordinary Differential Equations :

analysis which studies the numerical solution of ordinary

differential equations (ODEs). This field is also known under the

name numerical integration, but some people reserve this term for

the computation of integrals.

which case we have to satisfy ourselves with an approximation to

the solution. The algorithms studied here can be used to compute

such an approximation. An alternative method is to use techniques

from calculus to obtain a series expansion of the solution.

disciplines, for instance in mechanics, chemistry, biology, and

economics. In addition, some methods in numerical partial

differential equations convert the partial differential equation into

an ordinary differential equation, which must then be solved.

numerically such as The Euler Method and The Backward Euler

Method. After that, other methods have emerged (which are

generally more accurate and efficient).

the differential equation y' = y,y(0) = 1. Blue: the

Euler method, Green: the midpoint method and

Red: the exact solution, y = et. The step size is h =

1.0.

Figure (1)

5

II – Runge-Kutta Methods :

i- Introduction :

equations by using a trial step at the midpoint of an interval to

cancel out lower-order error terms. The second-order formula is

k 1 =h f x n , y n

k 2=h f x n1/ 2 h , y n 1/ 2 k 1

3

y n1 = y n k 2 O h

Taylor formula where

2

y x n1 = y n h f n h / 2 ! [ f x n f n f y n ]

so it's possible to develop formula equivalent to third, fourth,

fifth or even higher order Taylor formula, which do not involve

derivatives of f .

Taylor series formula

y n1 = y n h y n y n y n y n

2! 3! 4!

differentiating y'=f(x,y) is too lengthy and tedious but not

difficult.

6

The formula obtained after the derivation is

1

y n1 = y n w 1 2w 2 2w 3 w 4

6

where ;

w 1 =hf x n , y n

1 1

w 2 =hf x n h , y n w 1

2 2

1 1

w3=h f x n h , y n w 2

2 2

w 4=hf x n h , y n w 3

term Taylor series above formula and hence it's fourth order

method.

Example :

Apply the Runge-Kutta method to the IVP

'

y =1− x4y ; y 0=1

to find y(0.2). Take h = 0.1 and use six digits.

Solution :

n x y w=h(1-x+4y) Δ y

0 0.00 1.00000 0.500000 0.50000

0.05 1.25000 0.595000 1.19000

0.05 1.29750 0.614000 0.22800

0.10 1.30700 0.612800 0.612800

1

y1 =1 2.5228=1.420466

6 2.5228

7

n x y w=h(1-x+4y) Δ y

1 0.10 1.42046 0.65818 0.65818

0.15 1.74955 0.78482 1.56964

0.15 1.81282 0.81014 1.42029

0.20 1.82553 0.81021 0.81021

1

y 2 =1.420466 4.45832=2.44469

6 4.45832

8

iii- Computer-Aided 4th Order Runge-Kutta

Method :

that firstly appeared in 1991. Its design philosophy emphasizes

code readability. Python's core syntax and semantics are

minimalistic, while the standard library is large and

comprehensive. Its use of whitespace as block delimiters is

unusual among popular programming languages.

object oriented, imperative, and functional) and features a fully

dynamic type system and automatic memory management,

similar to Perl, Ruby, Scheme, and Tcl. Like other dynamic

languages, Python is often used as a scripting language.

managed by the non-profit Python Software Foundation, which

maintains the de facto standard definition of the language in

CPython, the reference implementation.

Palm Handhelds, and Nokia mobile phones. Python has also been

ported to the Java and .NET virtual machines.

"http://python.org/"

9

H:\Users\Mohammed\Desktop\Runge\RK4.py

2 # Th e f oll owi ng cod e r epr ese nts a 1st or der OD E s olv er usi ng Run ge Kut ta 4

me tho d

3 # Th e e qua tio n s hou ld be wri tte n a s y ' = f( x,y ) a nd it sho uld be va lid

ac cor din g t o p yth on' s s ynt ax

4 # Wr itt en by Moh amm ed Abb as "ab bas @ie ee. org " u sin g p yth on scr ipt ing la ngu age

v2 .6. 1

5 # La st Edi t : 9: 52 PM , 1 6th of Ap ril 20 09

6

7

8

9

10 d ef RK4 ():

11

12

13 # u ser 's inp ut wit h p rob lem gi ven s :

14

15 pri nt "Nu mer ica l 1 st ord er ODE so lve r u sin g R ung e-K utt a 4 me tho d"

16 pri nt 'Al gor ith m w rit ten by Mo ham med Ab bas "a bba s@i eee .or g"\ nUs ing py tho n

sc rip tin g l ang uag e v 2. 6.1 '

17 pri nt "\n Imp ort ant no tes :\ n1- Wh en ent eri ng the eq uat ion , p lea se mak e

su re you r u se * f or mul tip lic ati on and ** fo r e xpo nen tia tio n

ex : x ^2 sho uld be wr itt en as x** 2. \n2 - U se par ent hes es () to ski p

or der of pr ece den ce. "

18

19 # e qua tio n f (x, y) is ent ere d a s a st rin g :

20

21 eqn = raw _in put ("\ nPl eas e e nte r t he equ ati on as y' = " )

22

23 # i nit ial co ndi tio ns, st ep siz e a nd the po int of so lut ion :

24

25 x0 = i npu t(" Ple ase en ter x0 = ")

26

27 y0 = i npu t(" Ple ase en ter y( x0) = ")

28

29 h = in put ("P lea se def ine th e s tep si ze h = ")

30

31

32 s = in put ("P lea se spe cif y the po int at wh ich yo u n eed th e s olu tio n y (x) >

> ")

33

34 # n re pre sen ts how ma ny tim es the it era tio n i s d one us ing th e f oll owi ng

f or loo p t ech niq ue :

35

36 n = (s *1. 0)/ h

37 n = in t(n )

38

39 # f our fl oat ing po int ar ray s f or eac h c olu mn of the it era tio n i nit ial ly

z ero ed :

40

41 xA = [ 0.0 ,0. 0,0 .0, 0.0 ]

42 yA = [ 0.0 ,0. 0,0 .0, 0.0 ]

43 wA = [ 0.0 ,0. 0,0 .0, 0.0 ]

44 dyA = [0. 0,0 .0, 0.0 ,0. 0]

45

46

47

48

H:\Users\Mohammed\Desktop\Runge\RK4.py

49

50

51

52 # t his is th e b egi nni ng of the it era tio n p roc ess , ' for ' l oop sh oul d g o a s

m any ti mes as n is :

53

54 for i in ran ge( n):

55

56 # her e w e s imp ly tak e t he val ues of in iti al con dit ion va ria ble s x 0,y 0

ent ere d b y u ser :

57

58 xA [0] =x0

59 yA [0] =y0

60

61 #c hec k

62 #p rin t x A[0 ],y A[0 ]

63

64 # the n w e a ssi gn the m t o v ari abl es cal led x and y to hel p e val ()

fun cti on eva lua te the en ter ed equ ati on as pyt hon 's val id exp res sio n,

it the n h app ens ea ch and ev ery ti me we' d l ike to us e e val () fun cti on

wit h o the r v alu es :

65

66

67 x= xA[ 0]

68 y= yA[ 0]

69

70 # her e w e u se eva l() fu nti on to eva lua te the en ter ed exp res sio n w ith

x0, y0 val ues to ge t w 1(0 ) a nd the n w e u se w1( 0) to get th e n ext

val ue of y :

71

72 wA [0] = h * e val (eq n)

73 yA [1] = y A[0 ] + (0 .5* wA[ 0])

74

75 #c hec k

76 #p rin t w A[0 ],y A[1 ]

77

78 # her e's ho w t he nex t v alu e o f x is ob tai ned an d h ow we use th e

pre vio us tec hni que ag ain :

79

80 xA [1] = x 0+( 0.5 *h)

81 x= xA[ 1]

82 y= yA[ 1]

83

84 #c hec k

85 #p rin t x A[1 ]

86

87 wA [1] = h * e val (eq n)

88 yA [2] = y A[0 ] + (0 .5* wA[ 1])

89

90 #c hec k

91 #p rin t w A[1 ],y A[2 ]

92

93

94

95

96

97

98

H:\Users\Mohammed\Desktop\Runge\RK4.py

99

100 xA [2] = x 0+( 0.5 *h)

101 x= xA[ 2]

102 y= yA[ 2]

103

104 #c hec k

105 #p rin t x A[2 ]

106

107 wA [2] = h * e val (eq n)

108 yA [3] = y A[0 ] + (0 .5* wA[ 2])

109

110 #c hec k

111 #p rin t w A[2 ],y A[3 ]

112

113 xA [3] = x 0+h

114 x= xA[ 3]

115 y= yA[ 3]

116

117 #c hec k

118 #p rin t x A[3 ]

119

120

121 wA [3] = h * e val (eq n)

122

123 #c hec k

124 #p rin t w A[3 ]

125

126 # fin all y w e c alc ula te the va lue of dy fo r t he ite rat ion :

127

128 dy A[0 ] = wA [0]

129 dy A[1 ] = 2* wA[ 1]

130 dy A[2 ] = 2* wA[ 2]

131 dy A[3 ] = wA [3]

132

133 #c hec k

134 #p rin t d yA[ 0], dyA [1] ,dy A[2 ],d yA[ 3]

135

136 su m = dy A[0 ]+d yA[ 1]+ dyA [2] +dy A[3 ]

137

138 # thi s i s h ow we get yn +1 :

139

140 re sul t = yA [0] + ( sum /6. 0)

141

142 # bef ore th e i ter ati on end s, we' d l ike to us e s ome va lue fr om it for

the ne xt one :

143

144 x0 =xA [3] # x n+1

145 y0 =re sul t # y n+1

146

147 #c hec k

148 #p rin t x 0,y 0

149

150 # f unc tio n r etu rns th e f ina l r esu lt of the lo op whi ch' s t he sol uti on of

t he DE at the po int of in ter est an d t he val ue of thi s p oin t :

151 # u nli ke C a nd som e o the r l ang uag es, py tho n i s c apa ble of re tur nin g

m ult ipl e s tuf f n ot jus t o ne var iab le wit hou t t he exp lic it use of

p oin ter s.

152

H:\Users\Mohammed\Desktop\Runge\RK4.py

153

154

155 ret urn re sul t,s

156

157 # e nd of RK4 () fun cti on

158

159

160

161

162

163

164 # he re we sim ply ca ll the fu nct ion to re cei ve the de sir ed val ues :

165

166 f ina l,s = RK4 ()

167

168 # th en we rou nd the so lut ion to 5 dig its :

169

170 f ina l = ro und (fi nal ,5)

171

172 # th e o utp ut :

173

174 p rin t " \ny (%s ) = %f " %(s ,fi nal )

175

176 # sc rip t t erm ina tio n :

177

178 e sc = r aw_ inp ut( "\n \nP res s a ny key to en d . .." )

179

3- A Sample Runtime :

previous example.

Numerical 1st order ODE solver using Runge-Kutta 4 method

Algorithm written by Mohammed Abbas "abbas@ieee.org"

Using python scripting language v 2.6.1

Important notes :

1- When entering the equation, please make sure your use * for multiplication

and ** for exponentiation ex: x^2 should be written as x**2.

2- Use parentheses () to skip order of precedence.

Please enter x0 = 0

Please enter y(x0) = 1

Please define the step size h = 0.1

Please specify the point at which you need the solution y(x) >> 0.2

y(0.2) = 2.444690

14

III – Utilizing Runge-Kutta Method

In Solving Higher Order

Differential Equations :

Any differential equation of order n can be written as a system of

n first-order differential equations. Given an explicit ordinary

differential equation of order n and dimension 1,

' '' n−1 n

F x , y , y , y ,..... , y = y

we define a new family of unknown functions

n−1

y n := y

system of differential equations with order 1 and dimension n.

'

y1 = y 2

'

y 2= y 3

.

.

.

'

y n−1 = y n

'

y n =F y n ,.... , y 1 , x

'

y = F x , y ; with y := y ,..... , y n

15

Suppose we obtained a system from a higher order DE to be as

follows :

' '

x = f t , x , y , y = g t , x , y ; x 0= x 0 , y 0= y0

1

x n1= x n v 12 v 22 v 3 v 4

6

1

y n1 = y n w 1 2w 2 2w 3w 4

6

where :

v1 =hf t n , x n , y n

w 1 =hg t n , x n , y n

1 1 1

v 2 =hf t n h , x n v1 , y n w 1

2 2 2

1 1 1

w 2 =hg t n h , x n v 1 , y n w 1

2 2 2

1 1 1

v 3=hf t n h , x n v 2 , y n w 2

2 2 2

1 1 1

w 3 =hg t n h , x n v 2 , y n w 2

2 2 2

v 4 =hf t n h , x n v 3 , y n w 3

w 3 =hg t n h , x n v 3 , y n w 3

formula error is O h 4 . This method is sufficiently accurate.

16

Example :

Use Runge-Kutta method with step size h = 0.25 to compute

x(0.5) for the IVP x ' ' −tx ' − x=0 ; x 0=0 , x ' 0=1

Use five digits.

Solution :

'

x = y= f

'

y = xty=g

x 0=0 , y 0=1

n t x y V=hf W=hg Δx Δy

0 0.000 0.00000 1.0000 0.25000 0.00000 0.25000 0.00000

0.125 0.12500 1.0000 0.25000 0.06250 0.50000 0.12500

0.125 0.12500 1.0313 0.25783 0.06347 0.51566 0.12696

0.250 0.25783 1.0635 0.26588 0.13093 0.26588 0.13093

x 1=00.25526=0.25526

y1 =10.063815=1.0638 0.28853 0.063815

n t x y V=hf W=hg Δx Δy

1 0.250 0.25526 1.0638 0.26595 0.13030 0.26595 0.13030

0.375 0.38824 1.1290 0.28225 0.20290 0.56450 0.40580

0.375 0.39639 1.1653 0.29133 0.20848 0.58266 0.41696

0.500 0.54659 1.2723 0.31808 0.29569 0.31808 0.29569

x 0.5≈ x 2 =0.255260.28853=0.54379

' 0.28853 0.20813

x 0.5= y 0.5≈ y 2 =1.06380.20813=1.2719

17

Although we took n = 2 only, the total error made in computing

x(0.5) is 0.00004 which is much better than any of the second

order methods with n = 5.

1- Modeling and Analysis of Dynamic Systems

Publisher: Wiley; 3rd edition (August 6, 2001)

ISBN-13: 978-0471394426

By Charles M. Close, Dean K. Frederick and Jonathan

C. Newell

Publisher: Dar Teba Press

By Professor Dr. Reda El Barkouky

Publisher: O'Reilly Media, Inc.; 3rd edition (July 16, 2008)

ISBN-13: 978-0596513986

By Mark Lutz

18

- Numerical MethodsUploaded byvgnsh
- RK4 MethodUploaded byfurqanhamid
- Computer Methods for Solving Dynamic Separation ProblemsUploaded byrobayo_fy
- MATLAB Course - Part 2Uploaded byROBERT
- Chapter 1.1 – 1.8 QuizUploaded byspeterlee6253
- Equations With Defined VariableUploaded byzuft
- 1510 _Differential Equations in MATLABUploaded byGanesh P Prajapat
- UCL Notes on 1st Order PDEsUploaded byIslam Iman Dan Ihsan
- 55-157-1-PB.pdfUploaded bykirti
- Bsc Math Syllabus of Physical SciencesUploaded bydhondi1990
- vit 4years ece syallabusUploaded bypranavateja12399
- Gate MathematicsUploaded bybobjee
- DIFFRENTIAL EQUATION.pdfUploaded byANURAG
- Ground WaterUploaded bysanojk_2000
- Math 2301 s 12016Uploaded byJohn
- CHE3482011915035 (1)Uploaded bysolomonc123
- Analytic Solutions to Algebraic EquationsUploaded byJuan Pastor Ramos
- pavan docUploaded bysweet2shine
- 2009 DE Solutions (Mu).pdfUploaded byMark Vincent Esmeralda Mamigo
- 12. Mathematics JntukUploaded byds_kumar74
- Upsc Mains SyllabusUploaded byRitesh Kumar
- PHDbrochure 2ndsem 2018 19Uploaded bypiyushjindal98
- IJCKUploaded byΓιάννης Μουζάκης
- 9334 Hood d ExcelodeUploaded byRémy
- Math11ae Ptc-Acbet VerUploaded byferdie marcos
- Impactpaper.pdfUploaded byAravind Bhashyam
- 9901033Uploaded byPalash Swarnakar
- jntuk_m_tech_r13_cad&cam_syllabus.pdfUploaded byLohitha Polisetty
- ECM6Lecture3Vietnam_2014Uploaded byduyvu
- probsheet4.unit4.15Uploaded byPriyadarshini Krishnaswamy

- On a Rich Configuration Related to Tangent Circles in a TriangleUploaded bySAIKAT SENGUPTA
- ENG 1005 Notes (Mathematics)Uploaded bySiddhant
- random test yo!Uploaded byMeeka0917
- jee advanced paperUploaded byGaurav Yadav
- Microsoft Word - Practice Test-02 - 4 Year Program.docUploaded byChhavi Sadan
- Praxis MathUploaded bymalluboy
- Indicadores de Logro 2 PeriodoUploaded byLays Medeiros
- Piping IsometricsUploaded byRaphaël Diop
- SOF_CLASS 1Uploaded byUdhaya Sankar
- IJARCCE7DUploaded byParamesh Waran
- The Causal Relationships Between Performance Drivers and OutcomesUploaded byKenneth Byangwa
- Siggraph PinocchioUploaded bycarcorice
- IE27_04_PMFPDFUploaded byCristina de los Reyes
- Pictgram NotesUploaded byWajahatAbbasWajeeh
- ImprovedUploaded bypramod2604
- D S Lecture 8 &9 - Optimization of Linear ModelsUploaded byKimberly Brown
- Mon Math 211Uploaded bybjoaisdjofiwjeoijfiw
- Manit Choudhary Number SystemUploaded byShashidhar Reddy
- backprop.mUploaded bykjahdkajs
- Math – the Commons Math User Guide - Numerical AnalysisUploaded byJean claude onana
- UcamasUploaded bydaya
- Cape Pure MathematicsUploaded byRoland Connor
- Elmer Grid ManualUploaded byBi8ikity
- CHAPTER 05 - Public-key CryptographyUploaded byP
- 2010 - Estimation of Static Formation Temperatures in GeothermalUploaded byOsiris Flores
- bpc5_ch07-02Uploaded byPintohedfang
- Math 060 Scc SyllabusUploaded byapi-3808536
- STA_5325_HW_2_Ramin_ShamshiriUploaded byRaminShamshiri
- An Introduction to the Extended Kalman FilterUploaded byVu Duc Truong
- Motion_In_A_Straight_Line.pdfUploaded byRwik Dutta