Scilab/C4/ODE-Euler-methods/English
Title of script: Solving ODEs using Euler Methods
Author: Shamika
Keywords: ODEs, Euler method, modified Euler method, video tutorial
Visual Cue | |
---|---|
Slide 1 | Dear Friends,
Welcome to the Spoken Tutorial on “Solving ODEs using Euler Methods” |
Slide 2 -Learning Objective Slide | At the end of this tutorial, you will learn how to:
|
Slide 3-System Requirement slide | To record this tutorial, I am using
|
Slide 4- Prerequisites slide | To practise this tutorial, a learner
To learn Scilab, please refer to the relevant tutorials available on the Spoken Tutorial website. |
Slide 5- Euler Method | In Euler method, we get an accurately approximate solution of the ODE.
|
Slide 6- Example | Let us solve an example using Euler method.
y dash is equal to minus two t minus y.
|
Open Euler_ode.sci on Scilab Editor | Let us look at the code for Euler method.
|
Highlight
Euler_ode(f, tinit, yinit, h, N)
|
We define the function Euler underscore o d e with arguments f, t init, y init, h and n
where
|
Highlight
t = zeros(N+1, 1)
|
Then we initialize the values of t and y to vectors of zeros. |
Highlight
t(1) = tinit
|
We place the initial values of t and y in t of one and y of one respectively. |
Highlight
for j = 1:N t(j+1) = t(j) + h y(j + 1) = y(j) + h*f(t(j), y(j)) end |
Then we iterate from one to N to find the value of y.
|
Highlight
endfunction
|
Finally we end the function. |
Click on Execute and select Save and Execute | Save and execute the file Euler underscore o d e dot sci |
Switch to Scilab console | Switch to Scilab console the solve the example problem. |
Type on console
deff('[ydot]=f(t,y)','ydot=(-2*t)-y') |
We define the function by typing
d e f f open paranthesis open single quote open square bracket y dot close square bracket equal to f of t comma y close single quote comma open single quote y dot equal to open paranthesis minus two asterisk t close paranthesis minus y close single quote close paranthesis
|
Type on console
tinit=0 |
Then type t init is equal to zero.
Press Enter. |
Type on console
yinit=-1 |
Type y init is equal to minus one.
Press Enter |
Type on console
h=0.1 |
Type step length h is equal to zero point one.
Press Enter. |
Type on console
N=5 |
The step length is zero point one, and we have to find the value of y at zero point five.
At each iteration, the value of t will be increased by zero point one.
|
Type on console
[t, y] = Euler_ode(f, tinit, yinit, h, N) |
To call the function, type
|
Show console | The value of y at t equal to zero point five is shown. |
Slide 7- Modified Euler Method | Now let us look at Modified Euler method.
|
Slide 8- Example | Let us solve this example using Modified Euler method.
|
Open ModiEuler_ode.sci on Scilab Editor | Let us look at the code for Modified Euler method on Scilab Editor. |
Highlight
ModiEuler_ode(f, tinit, yinit, h, N)
|
We define the function with arguments f, t init, y init, h and n
where
|
Highlight
t = zeros(N+1,1) y = zeros(N+1,1) |
Then we initialize the arrays for y and t. |
Highlight
t(1) = tinit y(1) = yinit |
We place the initial values of t and y in t of one and y of one respectively. |
Highlight
for j = 1:N t(j+1) = t(j) + h y(j+1) = y(j) + h*f(t(j), y(j)) y(j+1) = y(j) + h*(f(t(j),y(j)) + f(t(j + 1),y(j)+h*f(t(j),y(j))))/2; end |
We implement Modified Euler Method here.
|
Click on Execute and select Save and Execute | Save and execute the file Modi Euler underscore o d e dot sci. |
Switch to Scilab console | Switch to Scilab console. |
Type clc
Press enter |
Clear the screen by typing c l c.
Press Enter. |
Type on console
deff('[ydot]=f(t,y)','ydot=t+y+t*y') |
Define the function by typing
d e f f open paranthesis open single quote open square bracket y dot close square bracket equal to f of t comma y close single quote comma open single quote y dot equal to t plus y plus t asterisk y close single quote close paranthesis
|
Type on console
tinit=0 |
Then type t init equal to zero
and press Enter |
Type on console
yinit=1 |
Type y init equal to one
and press Enter. |
Type on console
h=0.01 |
Then type h equal to zero point zero one
and press Enter. |
Type on console
N=10 |
Type capital N equal to ten.
|
Type on console
[t, y] = ModiEuler_ode(f, tinit, yinit, h, N) |
Then call the function modi euler underscore o d e by typing
open square bracket t comma y close square bracket equal to modi euler underscore o d e open paranthesis f comma t init comma y init comma h comma capital N close paranthesis Press Enter. |
Show console | The value of y at t equal to zero point one is shown. |
Slide 9- Example | Let us summarize this tutorial.
|
Show Slide 10
Title: About the Spoken Tutorial Project
|
* About the Spoken Tutorial Project
|
Show Slide 11
Title: Spoken Tutorial Workshops The Spoken Tutorial Project Team
|
The Spoken Tutorial Project Team
|
Show Slide 12
Title: Acknowledgement
|
* Spoken Tutorial Project is a part of the Talk to a Teacher project
|
This is Ashwini Patil signing off. Thanks for joining. |