Difference between revisions of "Scilab/C4/Integration/English"

From Script | Spoken-Tutorial
Jump to: navigation, search
Line 25: Line 25:
 
* Apply the algorithm to each '''interval'''
 
* Apply the algorithm to each '''interval'''
 
* Calculate the '''composite value of the integral'''  
 
* Calculate the '''composite value of the integral'''  
 
 
  
 
|-
 
|-
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Slide 4-System Requirement slide
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Slide 4-System Requirement slide
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * To record this tutorial, I am using '''Ubuntu 12.04''' as the operating system with '''Scilab 5.3.3''' version  
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * To record this tutorial, I am using  
 
+
*'''Ubuntu 12.04''' as the operating system  
 
+
*and '''Scilab 5.3.3''' version  
  
 
|-
 
|-
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Slide 5- Prerequisites slide
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Slide 5- Prerequisites slide
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * Before practising this tutorial, a learner should have basic knowledge of '''Scilab and Integration using Numerical Methods'''
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * Before practising this tutorial, a learner should have basic knowledge of  
 
+
*'''Scilab''' and
* For Scilab, please refer to the relevant tutorials available on the '''Spoken Tutorial '''website.
+
*'''Integration using Numerical Methods'''
 
+
  
 +
* For '''Scilab''', please refer to the relevant tutorials available on the '''Spoken Tutorial '''website.
  
 
|-
 
|-
Line 47: Line 45:
 
* Study of how the numerical value of an '''integral '''can be found
 
* Study of how the numerical value of an '''integral '''can be found
 
* It is used when exact mathematical integration is not available
 
* It is used when exact mathematical integration is not available
* It approximates a definite '''integral '''from values of the <br/> '''integrand '''
+
* It approximates a definite '''integral '''from values of the '''integrand '''
 
+
 
+
  
 
|-
 
|-
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Slide 7,8- Composite Trapezoidal Rule-I
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Slide 7,8- Composite Trapezoidal Rule-I
| 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 Composite Trapezoidal Rule. This rule''' is
+
| 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 '''Composite Trapezoidal Rule'''. This rule is
  
 
* The extension of '''trapezoidal rule'''
 
* The extension of '''trapezoidal rule'''
 
* We divide the interval '''a comma b '''into '''n''' equal intervals  
 
* We divide the interval '''a comma b '''into '''n''' equal intervals  
 +
 +
 
* Then,
 
* Then,
 
* '''h equal to b minus a divided by n''' is the common length of the intervals  
 
* '''h equal to b minus a divided by n''' is the common length of the intervals  
 +
 +
 
* Then '''composite trapezoidal rule '''is given by  
 
* 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'''
 
* '''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'''
 
 
  
 
|-
 
|-
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Slide 9- Example
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Slide 9- Example
  
 +
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Let us solve an example using '''composite trapezoidal rule'''.
  
 
+
Assume the number of intervals '''n''' is equal to ten.
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * Let us solve an example using '''composite trapezoidal rule''':
+
* Assume the number of intervals '''n''' is equal to ten.
+
 
+
 
+
  
 
|-
 
|-
Line 86: Line 81:
  
 
'''I1 = (h/2)*(2*sum(f(x)) - f(x(1)) - f(x(n+1)))'''
 
'''I1 = (h/2)*(2*sum(f(x)) - f(x(1)) - f(x(n+1)))'''
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * Let us look at the code for C'''omposite Trapezoidal Rule '''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;"|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. '''
+
 
 +
* 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
 
* '''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'''
+
* We find the value of the integral and store it in '''I one'''
 
+
 
+
  
 
|-
 
|-
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Click on Execute on Scilab editor and choose Save and Execute the code
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Click on Execute on Scilab editor and choose 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;"| * Click on '''Execute''' on '''Scilab editor''' and choose '''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;"| Click on '''Execute''' on '''Scilab editor''' and choose '''Save and Execute''' the code.
 
+
 
+
  
 
|-
 
|-
Line 107: Line 103:
  
 
'''Trap_composite(f, 0, 1, 10)'''
 
'''Trap_composite(f, 0, 1, 10)'''
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * Define the example function by typing:
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"|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'''
 
* '''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'''
+
* Press '''Enter'''
 
* Type  
 
* Type  
 
* '''Trap underscore composite open paranthesis f comma zero comma one comma ten close paranthesis'''
 
* '''Trap underscore composite open paranthesis f comma zero comma one comma ten close paranthesis'''
* Press '''enter'''
+
* Press '''Enter'''
* The answer is displayed on the console
+
* The answer is displayed on the '''console'''
 
+
 
+
  
 
|-
 
|-
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Slide 10, 11- Composite Simpson's Rule
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Slide 10, 11- Composite Simpson's Rule
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Next we shall study '''Composite simpson's rule. In this rule''' we  
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| 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  
 
* decompose the interval''' a comma b''' into '''''n is greater than 1 '''''subintervals of equal length  
 
* Apply '''Simpson's rule''' to each interval
 
* Apply '''Simpson's rule''' to each interval
 
* We get the value of the integral to be
 
* 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'''
+
** '''h by three multiplied by the sum of f zero, four into f one , two into f two to f n'''
 
+
 
+
  
 
|-
 
|-
Line 133: Line 125:
  
  
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * Let us solve an example using '''Composite Simpson's rule'''
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"|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'''
 
* 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'''
 
* Let the number of intervals be '''twenty'''
 
 
  
 
|-
 
|-
Line 162: Line 152:
  
 
'''I = (h/3)*(f(x(1)) + 2*sum(f(x1)) + 4*sum(f(x2)) + f(x(n)))'''
 
'''I = (h/3)*(f(x(1)) + 2*sum(f(x1)) + 4*sum(f(x2)) + f(x(n)))'''
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * Let us look at the code for '''Composite simpson's rule'''
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"|Let us look at the code for '''Composite simpson's rule'''
* '''We first define the function with parameters f , a , b , n. '''<br/> '''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 first define the function with parameters '''f , a , b , n. '''
* We find two sets of points
+
**'''f''' refers to the function we have to solve,  
* We find the value of the function with one set and multiply it with '''two'''
+
**'''a''' is the lower limit of the integral,  
* With the other set we find the value and multiply it with '''four'''
+
**'''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'''
 
* We sum these values and multiply it with '''h by three and store the final value in I'''
* Let us execute the code
 
  
  
 +
Let us execute the code
  
|-
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Click on Execute and choose
 
 
Save and execute the file
 
 
Simp_composite.sci
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * Save and execute the file
 
* '''Simp underscore composite dot s c i'''
 
  
  
 +
|-
 +
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Click on Execute and choose Save and execute the file Simp_composite.sci
 +
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"|Save and execute the file '''Simp underscore composite dot s c i'''
  
 
|-
 
|-
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Switch to Scilab Console
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Switch to Scilab Console
  
'''Type '''
+
Type '''clc'''
 
+
 
+
'''clc'''
+
  
  
Line 196: Line 182:
  
 
'''Simp_composite( f, 1, 2 20)'''
 
'''Simp_composite( f, 1, 2 20)'''
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * Let me clear the screen first.
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"|Let me clear the screen first.
* Define the function given in the example by typing
+
 
 +
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'''
 
* '''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'''
+
* Press '''Enter'''
* '''Type Simp underscore composite open paranthesis f comma one comma two comma twenty close paranthesis'''
+
* Type '''Simp underscore composite open paranthesis f comma one comma two comma twenty close paranthesis'''
* Press '''enter'''
+
* Press '''Enter'''
* The answer is displayed on the console
+
  
  
 +
The answer is displayed on the console.
  
 
|-
 
|-
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Slide 13, 14- Composite Midpoint Rule
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Slide 13, 14- Composite Midpoint Rule
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Let us now look at '''Composite Midpoint Rule. It'''
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Let us now look at '''Composite Midpoint Rule.'''
* Integrates polynomials of degree one or less
+
* It integrates polynomials of degree one or less
 
* Divides the interval '''a comma b into n subintervals''' of equal width
 
* Divides the interval '''a comma b into n subintervals''' of equal width
* Finds the '''midpoint '''of each interval indicated by '''x i '''
+
* Finds the midpoint of each interval indicated by '''x i '''
 
* We find the sum of the values of the integral at each midpoint  
 
* We find the sum of the values of the integral at each midpoint  
 
 
  
 
|-
 
|-
Line 224: Line 209:
 
* '''We are given a function one minus x square d x in the interval zero to one point five'''
 
* '''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'''
 
* We assume '''n''' is equal to''' twenty'''
 
 
  
 
|-
 
|-
Line 244: Line 227:
  
 
'''I = h*sum(f(x))'''
 
'''I = h*sum(f(x))'''
 +
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"|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  
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * Let us look at the code for '''Composite Midpoint rule'''
+
* '''We first define the function with parameters f , a , b , n. '''<br/> '''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  
+
 
+
 
+
  
 
|-
 
|-
Line 259: Line 243:
  
 
Save and execute the file mid_composite.sci
 
Save and execute the file mid_composite.sci
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * Save and execute the file '''mid underscore composite dot s c i '''
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"|Save and execute the file '''mid underscore composite dot s c i '''
 
+
 
+
  
 
|-
 
|-
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| On the Scilab Console type:
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| On the Scilab Console type: '''clc'''
 
+
 
+
'''clc'''
+
  
  
Line 274: Line 253:
  
 
Type '''mid_composite(f, 0, 1.5, 20)'''
 
Type '''mid_composite(f, 0, 1.5, 20)'''
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * Let me clear the screen
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"|Let me clear the screen
* We define the function given in the example by typing  
+
 
 +
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'''
 
* '''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'''
+
* Press '''Enter'''
* Then type <br/> '''mid underscore composite open paranthesis f comma zero comma one point five comma twenty close paranthesis'''
+
* Then type '''mid underscore composite open paranthesis f comma zero comma one point five comma twenty close paranthesis'''
* Press '''enter'''
+
* Press '''Enter'''
* The answer is displayed on the console
+
  
  
 +
The answer is displayed on the '''console'''
  
 
|-
 
|-
Line 290: Line 270:
 
* Develop '''Scilab''' code for '''numerical integration'''
 
* Develop '''Scilab''' code for '''numerical integration'''
 
* Find the value of an '''integral '''
 
* Find the value of an '''integral '''
 
 
  
 
|-
 
|-
Line 310: Line 288:
  
 
* If you do not have good bandwidth, you can download and watch it  
 
* If you do not have good bandwidth, you can download and watch it  
 
  
  
Line 334: Line 311:
  
 
* For more details, please write to contact at spoken hyphen tutorial dot org  
 
* For more details, please write to contact at spoken hyphen tutorial dot org  
 
  
  
Line 354: Line 330:
 
* It is supported by the National Mission on Education through ICT, MHRD, Government of India  
 
* It is supported by the National Mission on Education through ICT, MHRD, Government of India  
 
* More information on this Mission is available at  
 
* More information on this Mission is available at  
* spoken hyphen tutorial dot org slash NMEICT hyphen Intro <br/>
+
* spoken hyphen tutorial dot org slash NMEICT hyphen Intro  
 
+
 
+
  
  
Line 362: Line 336:
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"|  
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"|  
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * This is Ashwini Patil signing off. Thank you for joining.  
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * This is Ashwini Patil signing off. Thank you for joining.  
 
 
  
 
|}
 
|}

Revision as of 08:04, 22 December 2013

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
  • and 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