Scilab/C4/ODE-Applications/English
Title of script: Solving ODEs using Scilab ode Function
Author: Shamika
Keywords: ODEs
|
|
---|---|
Slide 1 | Dear Friends,
Welcome to the Spoken Tutorial on “Solving ODEs using Scilab ode Function” |
Slide 2 -Learning Objective Slide | At the end of this tutorial, you will learn how to:
|
Slide 3 -Learning Objective Slide | The typical examples we will be solving are:
|
Slide 4-System Requirement slide | To record this tutorial, I am using
|
Slide 5- Prerequisites slide | To practise this tutorial, a learner
To learn Scilab, please refer to the relevant tutorials available on the Spoken Tutorial website. |
Slide 6- ode Function | The ode function is an ordinary differential equation solver.
|
Slide 7- Motion of Simple pendulum | Consider the motion of simple pendulum.
|
Slide 8- Motion of Simple pendulum | Then the position of the pendulum is described by
theta double dash t minus g by l into sin of theta t equal to zero.
|
Slide 9- Motion of Simple pendulum | For the given initial conditions, we have to solve the ODE within the time range zero less than equal to t less than equal to five.
|
Open Pendulum.sci on Scilab Editor | Let us look at the code for solving this problem.
|
Highlight
y0=[%pi/4 0]'; t0=0; t=0:1:5
|
The first line of the code defines the initial conditions of the ODE.
|
Highlight
function dy=Pendulum(t, y) dy(1) = y(2); dy(2) = (9.8/0.5)*sin(y(1)); endfunction
|
Next, we convert the given equation to a system of first order ODEs.
|
Highlight
y=ode(y0,t0,t,Pendulum)
|
Then we call the ode function with arguments y zero, t zero, t and the function Pendulum. |
Highlight
plot(t,y(1,:),'-*',t,y(2,:),'-')
|
The solution to the equation will be a matrix with two rows.
|
Click on Execute and select Save and Execute | Save and execute the file Pendulum dot sci |
Show plot | The plot shows how the values of y and y dash vary with time. |
Switch to Scilab console | Switch to Scilab console |
Type y
Press Enter |
If you want to see the values of y, type y on the console and press Enter.
|
Slide 10- Van der Pol Equation | Let us solve Van der Pol equation using the ode function.
v double dash of t plus epsilon into v of t square minus one into v dash of t plus v of t equal to zero.
|
Open Vanderpol.sci on scilab editor | Let us look at the code for Van der Pol equation.
|
Highlight
y0=[1 0]'; t0=0; t=2:1:10;
|
We define the initial conditions of the ODEs and time and then define the time range.
|
Highlight
function dy=Vanderpol(t, y) dy(1) = y(2); dy(2) = -0.897*(y(1).^2 - 1)*y(2) - y(1); endfunction
|
Then we define the function van der pol and construct a system of first order ODEs.
|
Highlight
y=ode(y0,t0,t,Vanderpol)
|
Then we call ode function and solve the system of equations. |
Highlight
plot(t,y(1,:),'-',t,y(2,:),'--')
|
Finally we plot y and y dash versus t. |
Click on Execute and select Save and Execute | Save and execute the file van der pol dot sci. |
Show plot | The plot showing voltage versus time is shown.
|
Slide 11, 12- Lorenz system
|
The Lorenz system of equations is given by
The initial conditions are x one zero equal to minus ten, x two zero equal to ten and x three zero equal to twenty five.
|
Open Lorenz.sci on Scilab editor
|
Switch to Scilab editor and open Lorenz dot sci |
Highlight
x0=[-10 10 25]'; t0=0; t=0:1:25;
|
We start by defining the initial conditions of the ODEs.
|
Highlight
function dx=Lorenz(t, x) sigma = 10; r = 28; b = 8/3; dx(1) = sigma*(x(2) - x(1) ); dx(2) = ((1 + r) - x(3))*x(1) - x(2); dx(3) = x(1)*x(2) - b*x(3); endfunction
|
We define the function Lorenz and then define the given constants sigma, r and b. Then we define the first order ODEs. |
Highlight
x=ode(x0,t0,t,Lorenz)
|
Then we call the ode function to solve the Lorenz system of equations.
|
Highlight
plot(t,x(1,:),'**',t,x(2,:),'--', t,x(3,:),'..')
|
Then we plot x one, x two and x three versus time. |
Click on Execute and select Save and Execute | Save and execute the file Lorenz dot sci. |
Show plot | The plot of x one, x two and x three versus time is shown. |
Slide 13- Summary | Let us summarize this tutorial.
|
Show Slide 14
Title: About the Spoken Tutorial Project
|
* About the Spoken Tutorial Project
|
Show Slide 15
Title: Spoken Tutorial Workshops The Spoken Tutorial Project Team
|
The Spoken Tutorial Project Team
|
Show Slide 16
Title: Acknowledgement
|
* Spoken Tutorial Project is a part of the Talk to a Teacher project
|
This is Ashwini Patil from IIT Bombay signing off. Thanks for joining. |