Scilab/C4/Solving-Non-linear-Equations/English

From Script | Spoken-Tutorial
Revision as of 18:45, 12 February 2014 by Nancyvarkey (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

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 process 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.

Highlight as per narration

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

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.

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

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

Press Enter.

To know more about deff function, type help deff

Press Enter.

Tol=10^-5

Press enter

Bisection(a,b,f,Tol)

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 Secant's 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 method.


Open Secant dot sci on Scilab editor.

Highlight as per narration 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.
Highlight as per narration 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.

Highlight as per narration 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

Switch to Scilab console.


Type clc.

Press Enter.

a=2

Press enter


b=3

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.

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

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.

Secant(a,b,g)

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:

  • Develop Scilab code for different solving methods
  • Find the roots of nonlinear equation
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
  • http://spoken-tutorial.org/NMEICT-Intro


* 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