32 views

Original Title: Ode

Uploaded by manoj

- Advanced Engineering Mathematics 2130002
- CSIR UGC NET Mathematical Sciences Syllabus
- MATH 148 Handout
- common-1
- CEM 9
- Erich Miersemann - Partial Differential Equations (Lecture Notes) 2015
- Differential Equation
- An Introduction to Numerical Methods for the Solutions of Partial Differential Equations
- Scientist Getting Started Guide
- A Modern Guide to Crack GATE 2017 TechnoHerald
- Carolyn Kieran
- Solution Assignment Chapter 4 v2
- Tutorial 11 Solution
- Recurrence
- Jeca 2016
- Topic5 ODEs
- Mathcad - CAPE - 2008 - Math Unit 2 - Paper 03-2
- simultaneous_equations.pdf
- CHE654_2012_Homework4_Solutions.pdf
- Mathematics_PG.pdf

You are on page 1of 37

Aditya Sengupta

Indian Institute of Technology Bombay

apsengupta@iitb.ac.in

such as:

1

Difference Equations

ODEs in Scilab

such as:

1

Difference Equations

ODEs in Scilab

1

ODEs in Scilab

y = f (t, y )

Note: Scilab tools assume the differential equation to have been

written as first order system.

Some models are initially written in terms of higher-order

derivatives, but they can always be rewritten as first-order systems

by the introduction of additional variables

ODEs in Scilab

y = f (t, y )

Note: Scilab tools assume the differential equation to have been

written as first order system.

Some models are initially written in terms of higher-order

derivatives, but they can always be rewritten as first-order systems

by the introduction of additional variables

ODEs in Scilab

y = f (t, y )

Note: Scilab tools assume the differential equation to have been

written as first order system.

Some models are initially written in terms of higher-order

derivatives, but they can always be rewritten as first-order systems

by the introduction of additional variables

ODEs in Scilab

Example

dx

= sin(2t)

dt

We can model this system using this code:

1

2

3

f u n c t i o n dx = f ( t , x )

dx = s i n ( 2 t ) ;

endfunction

ODEs in Scilab

Example

dx

= sin(2t)

dt

We can model this system using this code:

1

2

3

f u n c t i o n dx = f ( t , x )

dx = s i n ( 2 t ) ;

endfunction

ODEs in Scilab

Solution

1

x = cos(2t) + c

2

where c is a constant that depends on the initial value of the

problem.

ODEs in Scilab

Depending on the initial value, the plot will look like this:

ODEs in Scilab

The simulation tool we will use for solving ODEs in Scilab is the

ode function

The simplest calling sequence for ode is:

y=ode(y0, t0, t, f)

where y0 is the initial value at t0 and t contains the points in

time at which the solution is to be determined. f is the function

corresponding to

y = f (t, y )

ODEs in Scilab

t0 = 0.

Let us evaluate the ODE from t = 0:0.1:5.

The code is:

1

2

3

4

5

t0 = 0

x0 = 0.5

t = 0:0.1:5;

x = ode ( x0 , t0 , t , f ) ;

plot2d (t , x)

ODEs in Scilab

t0 = 0.

Let us evaluate the ODE from t = 0:0.1:5.

The code is:

1

2

3

4

5

t0 = 0

x0 = 0.5

t = 0:0.1:5;

x = ode ( x0 , t0 , t , f ) ;

plot2d (t , x)

ODEs in Scilab

ODEs in Scilab

derivatives, we need to rewrite them as first-order systems. We do

this by using variables to fill in the intermediate order derivaties.

For example, let us consider the system:

d 2y

= sin(2t)

dt 2

whose one solution we can easily guess to be y = (1/4)sin(2t)

ODEs in Scilab

derivatives, we need to rewrite them as first-order systems. We do

this by using variables to fill in the intermediate order derivaties.

For example, let us consider the system:

d 2y

= sin(2t)

dt 2

whose one solution we can easily guess to be y = (1/4)sin(2t)

ODEs in Scilab

equations:

dy /dt = z

dz/dt = sin(2t)

Therefore, we have the ode in the form:

dx/dt = f (t, x)

where dx and x are vectors:

x = [z; sin(2t)]

dx = [dy /dt; dz/dt]

We then proceed to replace z, dy /dt, and dz/dt with vector

components x(2), dx(1), and dx(2)

Aditya Sengupta, EE, IITB

ODEs in Scilab

equations:

dy /dt = z

dz/dt = sin(2t)

Therefore, we have the ode in the form:

dx/dt = f (t, x)

where dx and x are vectors:

x = [z; sin(2t)]

dx = [dy /dt; dz/dt]

We then proceed to replace z, dy /dt, and dz/dt with vector

components x(2), dx(1), and dx(2)

Aditya Sengupta, EE, IITB

ODEs in Scilab

equations:

dy /dt = z

dz/dt = sin(2t)

Therefore, we have the ode in the form:

dx/dt = f (t, x)

where dx and x are vectors:

x = [z; sin(2t)]

dx = [dy /dt; dz/dt]

We then proceed to replace z, dy /dt, and dz/dt with vector

components x(2), dx(1), and dx(2)

Aditya Sengupta, EE, IITB

ODEs in Scilab

1

2

3

4

f u n c t i o n dx = f ( t , x )

dx ( 1 ) = x ( 2 )

dx ( 2 ) = s i n ( 2 t )

endfunction

1

2

3

4

5

6

7

t = 0 : 0 . 0 1 : 4 %pi ;

y=ode ( [ 0 ; 1/2] , 0 , t , f ) ;

// Note t h e i m p o r t a n c e o f g i v i n g c o r r e c t s t a r t i n g v a l u e s .

Try t o p u t a l t e r n a t e s t a r t i n g v a l u e s and s e e t h e

difference .

plot2d (t , [ y ( 1 , : ) y (2 , : ) ] )

// The c u r v e i n b l a c k i s t h e f i n a l s o l u t i o n . The o t h e r c u r v e

i s f o r i l l u s t r a t i o n t o show t h e i n t e r m e d i a t e s t e p .

ODEs in Scilab

1

2

3

4

f u n c t i o n dx = f ( t , x )

dx ( 1 ) = x ( 2 )

dx ( 2 ) = s i n ( 2 t )

endfunction

1

2

3

4

5

6

7

t = 0 : 0 . 0 1 : 4 %pi ;

y=ode ( [ 0 ; 1/2] , 0 , t , f ) ;

// Note t h e i m p o r t a n c e o f g i v i n g c o r r e c t s t a r t i n g v a l u e s .

Try t o p u t a l t e r n a t e s t a r t i n g v a l u e s and s e e t h e

difference .

plot2d (t , [ y ( 1 , : ) y (2 , : ) ] )

// The c u r v e i n b l a c k i s t h e f i n a l s o l u t i o n . The o t h e r c u r v e

i s f o r i l l u s t r a t i o n t o show t h e i n t e r m e d i a t e s t e p .

ODEs in Scilab

Root Finding

the time that a specific event occurs.

For example, an engine being revved until it reaches a particular

speed- after which the gear is to be changed.

For such circumstances, we need to define a quantity that signals

the occurance of the event.

ODEs in Scilab

Root Finding

the time that a specific event occurs.

For example, an engine being revved until it reaches a particular

speed- after which the gear is to be changed.

For such circumstances, we need to define a quantity that signals

the occurance of the event.

ODEs in Scilab

Root Finding

the time that a specific event occurs.

For example, an engine being revved until it reaches a particular

speed- after which the gear is to be changed.

For such circumstances, we need to define a quantity that signals

the occurance of the event.

ODEs in Scilab

[y, rd] = ode("root", y0, t0, t, f, ng, g)

where g is a function that becomes zero valued when the

constraining event occurs and ng is the size of g.

rd is a vector that contains the stopping time as its first element.

ODEs in Scilab

[y, rd] = ode("root", y0, t0, t, f, ng, g)

where g is a function that becomes zero valued when the

constraining event occurs and ng is the size of g.

rd is a vector that contains the stopping time as its first element.

ODEs in Scilab

Example

Let us consider the example of the engine that is revved. We wish

to constrain the revving of the engine till it reaches a certain point.

We build a first order approximation of an engine using the

following code (call it engine.sci):

1

2

3

d_revs = %e( revs )

endfunction

unconstrained using the following code:

1

2

3

e x e c engine . sci

revs = ode ( 0 , 0 , 0 : 0 . 1 : 1 0 , engine ) ;

p l o t 2 d ( 0 : 0 . 1 : 1 0 , revs )

ODEs in Scilab

Example

Let us consider the example of the engine that is revved. We wish

to constrain the revving of the engine till it reaches a certain point.

We build a first order approximation of an engine using the

following code (call it engine.sci):

1

2

3

d_revs = %e( revs )

endfunction

unconstrained using the following code:

1

2

3

e x e c engine . sci

revs = ode ( 0 , 0 , 0 : 0 . 1 : 1 0 , engine ) ;

p l o t 2 d ( 0 : 0 . 1 : 1 0 , revs )

ODEs in Scilab

Example

Let us consider the example of the engine that is revved. We wish

to constrain the revving of the engine till it reaches a certain point.

We build a first order approximation of an engine using the

following code (call it engine.sci):

1

2

3

d_revs = %e( revs )

endfunction

unconstrained using the following code:

1

2

3

e x e c engine . sci

revs = ode ( 0 , 0 , 0 : 0 . 1 : 1 0 , engine ) ;

p l o t 2 d ( 0 : 0 . 1 : 1 0 , revs )

ODEs in Scilab

1

2

stop = 1 . 5 revs //We c h o o s e t o s t o p t h e e n g i n e when

t h e r e v s r e a c h t h e v a l u e 1 . 5 ( You can c h o o s e any

other value )

endfunction

constrained as above.

1

2

3

4

e x e c engine . sci

e x e c gearbox . sci

[ revs , stop_time ]= ode ( r o o t , 0 , 0 , 0 : 0 . 1 : 1 0 , engine , 1 ,

gearbox ) ;

p l o t 2 d ( [ 0 : 0 . 1 : stop_time ( 1 ) , stop_time ( 1 ) ] , revs )

ODEs in Scilab

1

2

stop = 1 . 5 revs //We c h o o s e t o s t o p t h e e n g i n e when

t h e r e v s r e a c h t h e v a l u e 1 . 5 ( You can c h o o s e any

other value )

endfunction

constrained as above.

1

2

3

4

e x e c engine . sci

e x e c gearbox . sci

[ revs , stop_time ]= ode ( r o o t , 0 , 0 , 0 : 0 . 1 : 1 0 , engine , 1 ,

gearbox ) ;

p l o t 2 d ( [ 0 : 0 . 1 : stop_time ( 1 ) , stop_time ( 1 ) ] , revs )

ODEs in Scilab

Compare the two graphs- can you see where the simulation was

halted in the second case?

ODEs in Scilab

Linear Systems

Since they appear so often, there are special functions for modeling

and simulating linear systems.

For instance, you can create a linear system thus:

1

2

s = poly (0 , s )

sys = s y s l i n ( c , 1 / ( s+1) )

1

2

3

4

5

6

7

8

t = 0:0.1:10;

y = c s i m ( s t e p , t , sys ) ;

plot2d (t , y) ;

z = c s i m ( s i n ( 5 t ) , t , sys ) ;

plot2d (t , z) ;

bode ( sys , 0 . 0 1 , 1 0 0 ) ;

ODEs in Scilab

Linear Systems

Since they appear so often, there are special functions for modeling

and simulating linear systems.

For instance, you can create a linear system thus:

1

2

s = poly (0 , s )

sys = s y s l i n ( c , 1 / ( s+1) )

1

2

3

4

5

6

7

8

t = 0:0.1:10;

y = c s i m ( s t e p , t , sys ) ;

plot2d (t , y) ;

z = c s i m ( s i n ( 5 t ) , t , sys ) ;

plot2d (t , z) ;

bode ( sys , 0 . 0 1 , 1 0 0 ) ;

ODEs in Scilab

Model and simulate your own systems

Use the help command to find more options

ODEs in Scilab

Thanks

ODEs in Scilab

- Advanced Engineering Mathematics 2130002Uploaded byLAV PARMAR
- CSIR UGC NET Mathematical Sciences SyllabusUploaded byaglasem
- MATH 148 HandoutUploaded byc9majid
- common-1Uploaded bymechgokul
- CEM 9Uploaded bytatoo1
- Erich Miersemann - Partial Differential Equations (Lecture Notes) 2015Uploaded bydelenda3
- Differential EquationUploaded byNadda Muhamad
- An Introduction to Numerical Methods for the Solutions of Partial Differential EquationsUploaded byeiro
- Scientist Getting Started GuideUploaded byPingo McGraw
- A Modern Guide to Crack GATE 2017 TechnoHeraldUploaded byprachi
- Carolyn KieranUploaded byMaja Cindrić
- Solution Assignment Chapter 4 v2Uploaded byJEAN
- Tutorial 11 SolutionUploaded byCK
- RecurrenceUploaded byjohn17321
- Jeca 2016Uploaded byDebasish
- Topic5 ODEsUploaded byMariozhan Alvarezbay
- Mathcad - CAPE - 2008 - Math Unit 2 - Paper 03-2Uploaded byNefta Baptiste
- simultaneous_equations.pdfUploaded byarilove rigsby
- CHE654_2012_Homework4_Solutions.pdfUploaded bymbolantenaina
- Mathematics_PG.pdfUploaded bypriyanka b
- B_Arch_VNIT_Overall_Syllabus_I_X_Sem_Final_March2018-1.pdfUploaded byAsmita
- DesUploaded bykesavaero1
- lecture_4Uploaded byRandhirKumar
- Project ReportUploaded bySagar Prajapati
- upUploaded byNisa Kaleci
- ChE212 Implicit Eqn Soln and OptimizationUploaded byJohann Zabaleta
- heat conduction1.pdfUploaded byVadim Khayms
- 19309board ExaminationUploaded byAnapurna Monga
- Main ActualUploaded byDhrubajyoti Biswas
- dance 3Uploaded byapi-279576217

- Pitt MechE HandbookUploaded byNathan MacIntire
- differential_equations_p3.pdfUploaded byRayYong
- New Syllabus Chem Engg Deg StdUploaded byHarsha
- Elementary Differential Equations 6th EditionUploaded byRakesh Sarma
- Ocean University of China, Supervisor_s InformationUploaded bysimplecobra
- A Comparison of Wort Chiller Water and Time Usage as a Function of Coolant Temperature and Flow RateUploaded bySachin Darji
- tum02disUploaded byapi-235495832
- Paper 1Uploaded byRakeshconclave
- On General Solutions of Einstein EquationsUploaded bySergiu Vacaru
- Chap17_Sec1Uploaded byPedro Ramirez
- Gate SyllabusUploaded byAnurag Prabhakar
- MATH 2411Uploaded byYktash
- HHT Alpha MethodUploaded bySasi Sudhahar Chinnasamy
- Gate SyllabusUploaded byRakesh Sharma
- CbcsUploaded byTrilok Akhani
- Discrete Dynamical SystemsUploaded byCarlos Augusto Sánchez Rondón
- ReportGodunov Method and Related Schemes for Nonlinear Hyperbolic ProblemsUploaded bybernardo.favini6840
- 3.29128Uploaded byali_raza117
- syllabiUploaded byadamtommy
- ECE-R09 Syllabus, 26.07.2012Uploaded byappuamreddy
- Proforma Piloting BDCUploaded byMat Harzick
- Preview of "The Core: Introductory Calculus…As It Should Be"Uploaded byUgochukwu C. Akwarandu
- EceUploaded bykarthick_mariner92
- UEM Sol to Exerc ContentsUploaded byEric Black
- Zijlema Lecturenotes ODE and SWEUploaded byRossy Dinda Pratiwi
- NUMERICAL SOLUTION OF REYNOLDS EQUATION USING DIFFERENTIAL TRANSFORM METHOD.Uploaded byIJAR Journal
- Chapter 1Uploaded byCharmaine Chu
- 15 b Sc With PhysicsUploaded byDébàshis Dash
- FP2 QPUploaded byChello Nick
- Differential Equations in MATLABUploaded bykensaii