Difference between revisions of "Scilab/C4/Solving-Non-linear-Equations/English"

From Script | Spoken-Tutorial
Jump to: navigation, search
(Created page with ''''Title of script''': '''Solving Nonlinear Equations using Numerical Methods''' '''Author: Shamika''' '''Keywords: Nonlinear equation, root, zero''' {| style="border-spacing…')
 
Line 25: Line 25:
 
* Solve '''nonlinear equations''' using numerical methods
 
* Solve '''nonlinear equations''' using numerical methods
 
* The methods we will be studying are
 
* The methods we will be studying are
* Bisection method
+
* '''Bisection method'''
* and Secant method
+
* and '''Secant method'''
  
 
* We will also develop '''Scilab''' code to solve '''nonlinear equations '''
 
* We will also develop '''Scilab''' code to solve '''nonlinear equations '''
Line 63: Line 63:
  
  
* In '''bisection method,''' we calculate the initial bracket of the '''root'''.  
+
* In '''bisection method,''' we calculate the '''initial bracket''' of the '''root'''.  
* Then we iterate through the bracket and halve its length.  
+
* Then we iterate through the '''bracket''' and halve its length.  
 
* We repeat this proces until we find the solution of the equation.
 
* We repeat this proces until we find the solution of the equation.
  
Line 80: Line 80:
 
|-
 
|-
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Open '''Bisection.sci''' on Scilab Editor
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Open '''Bisection.sci''' on Scilab Editor
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * Open Bisection dot sci on Scilab editor
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * Open '''Bisection dot sci '''on '''Scilab editor'''
* Let us look at the code for Bisection method
+
* Let us look at the code for '''Bisection method'''
* We define the function Bisection with input arguments a b f and tol
+
* We define the function '''Bisection''' with input arguments '''a b f '''and '''tol'''
* Here a is the lower limit of the interval
+
* Here '''a''' is the lower limit of the interval
* b is the upper limit of the interval
+
* '''b '''is the upper limit of the interval
* f is the function to be solved
+
* '''f''' is the function to be solved
* and tol is th etolerance level
+
* and '''tol''' is the''' tolerance level'''
 
* We specify the maximum number of iterations to be equal to hundred.  
 
* We specify the maximum number of iterations to be equal to hundred.  
* We find the midpoint of the interval and iterate till the value calculated is within the specified '''tolerance range'''.  
+
* We find the '''midpoint of the interval '''and iterate till the value calculated is within the specified '''tolerance range'''.  
  
  
Line 97: Line 97:
  
  
Save and execute the file
+
'''Save and execute '''the file
  
 
|-
 
|-
Line 126: Line 126:
  
 
Press enter
 
Press enter
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Switch to Scilab console
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Switch to '''Scilab console'''
  
  
Line 132: Line 132:
  
  
Let a be equal to minus five  
+
Let '''a '''be equal to minus five  
  
 
Press enter
 
Press enter
  
  
Let b be equal to minus three.  
+
Let '''b''' be equal to minus three.  
  
 
Press enter
 
Press enter
Line 154: Line 154:
  
  
Let '''tol '''be equal to '''10 to the power of minus five'''
+
Let '''tol '''be equal to 10 to the power of minus five
  
 
'''Press enter'''
 
'''Press enter'''
Line 171: Line 171:
 
|-
 
|-
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Slide 12
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Slide 12
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Let us study Secant's method.  
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Let us study '''Secant's method'''.  
  
  
 
In '''Secan't method, '''the derivative is approximated by finite  
 
In '''Secan't method, '''the derivative is approximated by finite  
  
difference using two successive Pls use a simpler word. This word
+
difference using two successive '''iteration values.'''
 
+
will pose a problem for our translators.''Reply to nancy (12/23/2013, 11:33): "..."''
+
 
+
Changed. iteration values.  
+
  
 
|-
 
|-
Line 189: Line 185:
  
  
The two starting guesses are , '''p zero '''equal to two and '''p one '''equal to three.  
+
The two '''starting guesses''' are , '''p zero '''equal to two and '''p one '''equal to three.  
  
 
|-
 
|-
Line 196: Line 192:
  
  
Open Secant dot sci on Scilab editor
+
Open '''Secant dot sci '''on '''Scilab editor'''
  
  
We define the function secant with input arguments a, b and f
+
We define the function '''secant '''with input arguments '''a, b '''and '''f'''
  
  
a is first starting guess for the root
+
'''a''' is first starting guess for the root
  
  
b is the second starting guess and f is the function to be solved.  
+
'''b''' is the second starting guess and f is the function to be solved.  
  
  
Line 218: Line 214:
 
|-
 
|-
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Click on Execute and select Save and Execute
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Click on Execute and select Save and Execute
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Let me save and execute the code.  
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Let me '''save and execute '''the code.  
  
 
|-
 
|-
Line 249: Line 245:
  
 
Press enter
 
Press enter
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Switch to Scilab console
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Switch to '''Scilab console'''
  
  
Type clc
+
Type '''clc'''
  
Press enter
+
Press '''enter'''
  
  
Line 261: Line 257:
 
'''a '''equal to 2
 
'''a '''equal to 2
  
Press enter
+
Press '''enter'''
  
  
Line 268: Line 264:
 
'''b '''equal to 3
 
'''b '''equal to 3
  
Press enter
+
Press '''enter'''
  
  
Line 287: Line 283:
  
  
The value of the root is shown on the console
+
The value of the root is shown on the '''console'''
  
  

Revision as of 17:20, 12 February 2014

Title of script: Solving Nonlinear Equations using Numerical Methods

Author: Shamika

Keywords: Nonlinear equation, root, zero


Visual Cue


Narration
Slide 1 Dear Friends,

Welcome to the spoken tutorial on “Solving Nonlinear Equations using Numerical Methods

Slide 2,3 -Objectives At the end of this tutorial, you will learn how to:
  • Solve nonlinear equations using numerical methods
  • The methods we will be studying are
  • Bisection method
  • and Secant method
  • We will also develop Scilab code to solve nonlinear equations


Slide 4-System Requirements To record this tutorial, I am using
  • Ubuntu 12.04 as the operating system
  • and Scilab 5.3.3 version


Slide 5- Prerequisites Before practising this tutorial, a learner should have
  • basic knowledge of Scilab and
  • nonlinear equations

For Scilab, please refer to the Scilab tutorials available on the Spoken Tutorial website.

Slide 6 For a given function f , we have to find the value of x for which f of x is equal to zero.

This solution x is called root of equation or zero of function f

This process is called root finding or zero finding

Slide 7 We begin by studying Bisection Method.


  • In bisection method, we calculate the initial bracket of the root.
  • Then we iterate through the bracket and halve its length.
  • We repeat this proces until we find the solution of the equation.


Slide 8 Let us solve this function using Bisection method


Given

function f equal to two sin x minus e to the power of x divided by four minus one in the interval minus five and minus three.

Open Bisection.sci on Scilab Editor * Open Bisection dot sci on Scilab editor
  • Let us look at the code for Bisection method
  • We define the function Bisection with input arguments a b f and tol
  • Here a is the lower limit of the interval
  • b is the upper limit of the interval
  • f is the function to be solved
  • and tol is the tolerance level
  • We specify the maximum number of iterations to be equal to hundred.
  • We find the midpoint of the interval and iterate till the value calculated is within the specified tolerance range.


Click on Execute and select Save and Execute Let us solve the problem using this code.


Save and execute the file

Switch to Scilab console


On Scilab Console type,

a=-5

Press enter

b=-3

Press enter


deff('[y]=f(x)','y=(2*(sin(x))-((%e^x)/4)-1')

Press enter


Tol=10^-5

Press enter

Bisection(a,b,f,Tol)

Press enter

Switch to Scilab console


Let us define the interval.


Let a be equal to minus five

Press enter


Let b be equal to minus three.

Press enter


Define the function using deff function.

We type

deff open paranthesis open single quote open square bracket y close square bracket equal to f of x close single quote comma open single quote y equal to two asterisk sin of x minus open paranthesis open paranthesis percentage e to the power of x close paranthesis divided by four close paranthesis minus one close single quote close paranthesis


To know more about deff function, type help deff

Press enter


Let tol be equal to 10 to the power of minus five

Press enter


To solve the problem, type


Bisection open paranthesis a comma b comma f comma tol close paranthesis

Press enter


The root of the function is shown on the console

Slide 12 Let us study Secant's method.


In Secan't method, the derivative is approximated by finite

difference using two successive iteration values.

Slide 13 Let us solve this example using Secant method

The function is f equal to x square minus six.


The two starting guesses are , p zero equal to two and p one equal to three.

Open Secant.sci on Scilab Editor Before we solve the problem, let us look at the code for Secant meethod.


Open Secant dot sci on Scilab editor


We define the function secant with input arguments a, b and f


a is first starting guess for the root


b is the second starting guess and f is the function to be solved.


We find the difference between the value at the current point and the previous point.


We apply Secant's method and find the value of the root.


Finally we end the function

Click on Execute and select Save and Execute Let me save and execute the code.
Switch to Scilab console

Type on Scilab console


clc

Press enter


a=2

Press enter


b=3

Press enter


deff('[y]=g(x)','y=(x^2)-6')

Press enter


Secant(a,b,g)

Press enter

Switch to Scilab console


Type clc

Press enter


Let me define the initial guesses for this example. Type

a equal to 2

Press enter


Then type

b equal to 3

Press enter


We define the function using deff function.

Type

deff open paranthesis open single quote open square bracket y close square bracket equal to g of x close single quote comma open single quote y equal to open paranthesis x to the power of two close paranthesis minus six close single quote close paranthesis

Press enter


We call the function by typing

Secant open paranthesis a comma b comma g close paranthesis.

Press enter


The value of the root is shown on the console



Slide 14 Let us summarize this tutorial

In this tutorial we have learnt to:

  • Find the roots of nonlinear equation
  • Develop Scilab code for different solving methods


Slide 15- Assignment Solve this problem on your own using the two methods we learnt today.
Show Slide 16

Title: About the Spoken Tutorial Project

  • It summarises the Spoken Tutorial project
  • If you do not have good bandwidth, you can download and watch it


* Watch the video available at the following link
  • It summarises the Spoken Tutorial project
  • If you do not have good bandwidth, you can download and watch it



Show Slide 17

Title: Spoken Tutorial Workshops

The Spoken Tutorial Project Team

  • Conducts workshops using spoken tutorials
  • Gives certificates for those who pass an online test
  • For more details, please write to contact@spoken-tutorial.org


The Spoken Tutorial Project Team
  • Conducts workshops using spoken tutorials
  • Gives certificates for those who pass an online test
  • For more details, please write to contact at spoken hyphen tutorial dot org


Show Slide 18

Title: Acknowledgement

  • Spoken Tutorial Project is a part of the Talk to a Teacher project
  • It is supported by the National Mission on Education through ICT, MHRD, Government of India
  • More information on this Mission is available at


* Spoken Tutorial Project is a part of the Talk to a Teacher project
  • It is supported by the National Mission on Education through ICT, MHRD, Government of India
  • More information on this Mission is available at
  • spoken hyphen tutorial dot org slash NMEICT hyphen Intro


On previous slide This is Ashwini Patil signing off. Thanks for joining.

Contributors and Content Editors

Lavitha Pereira, Nancyvarkey