Difference between revisions of "Scilab/C4/Integration/English"
(Created page with ''''Title of script''': Numerical Methods for Integration '''Author: Shamika''' '''Keywords: Integration, Numerical Methods, integral''' {| style="border-spacing:0;" ! <center…') |
|||
Line 4: | Line 4: | ||
'''Keywords: Integration, Numerical Methods, integral''' | '''Keywords: Integration, Numerical Methods, integral''' | ||
+ | |||
Line 52: | Line 53: | ||
|- | |- | ||
| 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;"| '''Composite Trapezoidal 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''' | |
Line 69: | Line 70: | ||
| 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''': | | 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 | + | * 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:none;padding:0.097cm;"| | + | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Switch to Scilab editor |
+ | |||
+ | |||
+ | Highlight | ||
+ | |||
+ | '''<nowiki>function [I1] </nowiki><nowiki>= Trap_composite(f, a, b, n)</nowiki>''' | ||
+ | |||
+ | '''x = linspace(a, b, 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 C'''omposite 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 | + | * '''linspace''' function is used to create ten equal intervals between zero and one |
− | * '''We find the value of the integral and store it in | + | * '''We find the value of the integral and store it in I one''' |
Line 98: | Line 109: | ||
| 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 | ||
Line 108: | Line 119: | ||
|- | |- | ||
| 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;"| | + | | 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''' | + | * 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''' | ||
|- | |- | ||
− | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Slide 12- Example | + | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Slide 12- Example |
Line 123: | Line 135: | ||
| 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 | + | * Let the number of intervals be '''twenty''' |
Line 129: | Line 141: | ||
|- | |- | ||
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Switch to Scilab Editor and show the code for Simp_composite.sci | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| 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)))''' | ||
| 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. '''<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 two sets of points | * We find two sets of points | ||
− | * We find the value of the function with one set and multiply it with | + | * 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 | + | * With the other set we find the value and multiply it with '''four''' |
− | * We sum these values and multiply it with h by | + | * 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 | ||
Line 159: | Line 192: | ||
− | '''<nowiki>deff ('[y]=f(x)','y= | + | '''<nowiki>deff ('[y]=f(x)','y=1/(1+x^3)')</nowiki>''' |
− | '''Simp_composite( f, | + | '''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''' |
− | * 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 | ||
Line 177: | Line 210: | ||
| 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. It''' | ||
* Integrates polynomials of degree one or less | * Integrates polynomials of degree one or less | ||
− | * Divides the interval | + | * 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 191: | Line 223: | ||
| 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 this problem using '''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 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 are given a function one minus x square d x in the interval zero to one point five''' | ||
− | * We assume n is equal to | + | * We assume '''n''' is equal to''' twenty''' |
Line 200: | Line 232: | ||
Show the file mid_composite.sci | 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))''' | ||
Line 232: | Line 276: | ||
| 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''' |
− | * Press enter | + | * Press '''enter''' |
− | * Then type <br/> ''' | + | * Then type <br/> '''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 294: | Line 338: | ||
|- | |- | ||
− | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| '''Show Slide | + | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| '''Show Slide 12''' |
'''Title: Acknowledgement''' | '''Title: Acknowledgement''' | ||
Line 304: | Line 348: | ||
* More information on this Mission is available at | * More information on this Mission is available at | ||
− | * [http://spoken-tutorial.org/NMEICT-Intro | + | * [http://spoken-tutorial.org/NMEICT-Intro http://spoken-tutorial.org/NMEICT-][http://spoken-tutorial.org/NMEICT-Intro Intro] |
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * Spoken Tutorial Project is a part of the Talk to a Teacher project | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * 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 | * 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/> | ||
− | * | + | |
+ | |||
+ | |||
+ | |- | ||
+ | | 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. | ||
|} | |} |
Revision as of 10:16, 18 December 2013
Title of script: Numerical Methods for Integration
Author: Shamika
Keywords: Integration, Numerical Methods, integral
|
|
---|---|
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:
|
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
|
Slide 6- Numerical Integration | Numerical Integration is the:
|
Slide 7,8- Composite Trapezoidal Rule-I | Let us study Composite Trapezoidal Rule. This rule is
|
Slide 9- Example
|
* Let us solve an example using composite trapezoidal rule:
|
Switch to Scilab editor
function [I1] = Trap_composite(f, a, b, n) x = linspace(a, b, n+1)
|
* Let us look at the code for Composite Trapezoidal Rule on Scilab Editor
|
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
|
* Define the example function by typing:
|
Slide 10, 11- Composite Simpson's Rule | Next we shall study Composite simpson's rule. In this rule we
|
Slide 12- Example
|
* Let us solve an example using Composite Simpson's rule
|
Switch to Scilab Editor and show the code for Simp_composite.sci
function I = Simp_composite(f, a, b, n)
x1(i) = x(2*i) end for j = 2:n/2 x2(i) = x(2*i-1) end
|
* Let us look at the code for Composite simpson's rule
|
Click on Execute and choose
Save and execute the file Simp_composite.sci |
* Save and execute the file
|
Switch to Scilab Console
Type
|
* Let me clear the screen first.
|
Slide 13, 14- Composite Midpoint Rule | Let us now look at Composite Midpoint Rule. It
|
Slide 15- Example
|
Let us solve this problem using Composite Midpoint Rule
|
Switch to Scilab Editor
|
* Let us look at the code for Composite Midpoint rule
|
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:
|
* Let me clear the screen
|
Slide 16- Summary | Let us summarize this tutorial. In this tutorial we have learnt to:
|
Show Slide 17
Title: About the Spoken Tutorial Project
|
* Watch the video available at the following link
|
Show Slide 18
Title: Spoken Tutorial Workshops The Spoken Tutorial Project Team
|
The Spoken Tutorial Project Team
|
Show Slide 12
Title: Acknowledgement
|
* Spoken Tutorial Project is a part of the Talk to a Teacher project
|
* This is Ashwini Patil signing off. Thank you for joining.
|