Scilab/C4/Integration/English

From Script | Spoken-Tutorial
Revision as of 10:16, 18 December 2013 by Lavitha Pereira (Talk | contribs)

Jump to: navigation, search

Title of script: Numerical Methods for Integration

Author: Shamika

Keywords: Integration, Numerical Methods, integral


Visual Cue
Narration
Slide 1 Dear Friends,

Welcome to the Spoken Tutorial on “ Composite Numerical Integration

Slide 2,3 -Learning Objective Slide At the end of this tutorial, you will learn how to:
  • Develop Scilab code for different Composite Numerical Integration algorithms
  • Divide the integral into equal intervals
  • Apply the algorithm to each interval
  • Calculate the composite value of the integral


Slide 4-System Requirement slide * To record this tutorial, I am using Ubuntu 12.04 as the operating system with Scilab 5.3.3 version


Slide 5- Prerequisites slide * Before practising this tutorial, a learner should have basic knowledge of Scilab and Integration using Numerical Methods
  • For Scilab, please refer to the relevant tutorials available on the Spoken Tutorial website.


Slide 6- Numerical Integration Numerical Integration is the:
  • Study of how the numerical value of an integral can be found
  • It is used when exact mathematical integration is not available
  • It approximates a definite integral from values of the
    integrand


Slide 7,8- Composite Trapezoidal Rule-I Let us study Composite Trapezoidal Rule. This rule is
  • The extension of trapezoidal rule
  • We divide the interval a comma b into n equal intervals
  • Then,
  • h equal to b minus a divided by n is the common length of the intervals
  • Then composite trapezoidal rule is given by
  • The integral of the function F of x in the interval a to b is approximately equal to h multiplied by the sum of the values of the function at x zero to x n


Slide 9- Example


* Let us solve an example using composite trapezoidal rule:
  • Assume the number of intervals n is equal to ten.


Switch to Scilab editor


Highlight

function [I1] = Trap_composite(f, a, b, n)

x = linspace(a, b, n+1)


I1 = (h/2)*(2*sum(f(x)) - f(x(1)) - f(x(n+1)))

* Let us look at the code for Composite Trapezoidal Rule on Scilab Editor
  • We first define the function with parameters f , a , b , n. f refers to the function we have to solve, a is the lower limit of the integral, b is the upper limit of the integral and n is the number of intervals.
  • linspace function is used to create ten equal intervals between zero and one
  • We find the value of the integral and store it in I one


Click on Execute on Scilab editor and choose Save and Execute the code * Click on Execute on Scilab editor and choose Save and Execute the code


Switch to Scilab Console


deff ('[y]=f(x)','y=1/(2*x+1)')


Trap_composite(f, 0, 1, 10)

* Define the example function by typing:
  • d e f f open paranthesis open single quote open square bracket y close square bracket is equal to f of x close quote comma open quote y is equal to one by open paranthesis two asterisk x plus one close paranthesis close quote close paranthesis
  • Press enter
  • Type
  • Trap underscore composite open paranthesis f comma zero comma one comma ten close paranthesis
  • Press enter
  • The answer is displayed on the console


Slide 10, 11- Composite Simpson's Rule Next we shall study Composite simpson's rule. In this rule we
  • decompose the interval a comma b into n is greater than 1 subintervals of equal length
  • Apply Simpson's rule to each interval
  • We get the value of the integral to be
  • h by three multiplied by the sum of f zero, four into f one , two into f two to f n


Slide 12- Example


* Let us solve an example using Composite Simpson's rule
  • We are given a function one by one plus x cube d x in the interval one to two
  • Let the number of intervals be twenty


Switch to Scilab Editor and show the code for Simp_composite.sci


Highlight

function I = Simp_composite(f, a, b, n)


for i = 1:(n/2)-1

x1(i) = x(2*i)

end

for j = 2:n/2

x2(i) = x(2*i-1)

end


I = (h/3)*(f(x(1)) + 2*sum(f(x1)) + 4*sum(f(x2)) + f(x(n)))

* Let us look at the code for Composite simpson's rule
  • We first define the function with parameters f , a , b , n.
    f refers to the function we have to solve, a is the lower limit of the integral, b is the upper limit of the integral and n is the number of intervals.
  • We find two sets of points
  • We find the value of the function with one set and multiply it with two
  • With the other set we find the value and multiply it with four
  • We sum these values and multiply it with h by three and store the final value in I
  • Let us execute the code


Click on Execute and choose

Save and execute the file

Simp_composite.sci

* Save and execute the file
  • Simp underscore composite dot s c i


Switch to Scilab Console

Type


clc


deff ('[y]=f(x)','y=1/(1+x^3)')


Simp_composite( f, 1, 2 20)

* Let me clear the screen first.
  • Define the function given in the example by typing
  • d e f f open paranthesis open single quote open square bracket y close square bracket is equal to f of x close quote comma open quote y is equal to one divided by open paranthesis one plus x cube close paranthesis close quote close paranthesis
  • Press enter
  • Type Simp underscore composite open paranthesis f comma one comma two comma twenty close paranthesis
  • Press enter
  • The answer is displayed on the console


Slide 13, 14- Composite Midpoint Rule Let us now look at Composite Midpoint Rule. It
  • Integrates polynomials of degree one or less
  • Divides the interval a comma b into n subintervals of equal width
  • Finds the midpoint of each interval indicated by x i
  • We find the sum of the values of the integral at each midpoint


Slide 15- Example


Let us solve this problem using Composite Midpoint Rule
  • We are given a function one minus x square d x in the interval zero to one point five
  • We assume n is equal to twenty


Switch to Scilab Editor


Show the file mid_composite.sci


Highlight


function I = mid_composite(f, a, b, n)


x = linspace(a + h/2, b - h/2, n)


I = h*sum(f(x))


* Let us look at the code for Composite Midpoint rule
  • We first define the function with parameters f , a , b , n.
    f refers to the function we have to solve, a is the lower limit of the integral, b is the upper limit of the integral and n is the number of intervals.
  • We find the midpoint of each interval
  • Find the value of integral at each midpoint and then find the sum and store it in I.
  • Let us now solve the example


Click on Execute and choose

Save and execute the file mid_composite.sci

* Save and execute the file mid underscore composite dot s c i


On the Scilab Console type:


clc


deff ('[y]=f(x)','y=1-x^2')


Type mid_composite(f, 0, 1.5, 20)

* Let me clear the screen
  • We define the function given in the example by typing
  • d e f f open paranthesis open single quote open square bracket y close square bracket is equal to f of x close quote comma open quote y is equal to one minus x square close quote close paranthesis
  • Press enter
  • Then type
    mid underscore composite open paranthesis f comma zero comma one point five comma twenty close paranthesis
  • Press enter
  • The answer is displayed on the console


Slide 16- Summary Let us summarize this tutorial. In this tutorial we have learnt to:
  • Develop Scilab code for numerical integration
  • Find the value of an integral


Show Slide 17

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 18

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 12

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



* This is Ashwini Patil signing off. Thank you for joining.


Contributors and Content Editors

Lavitha Pereira, Nancyvarkey