SlideShare une entreprise Scribd logo
1  sur  6
Télécharger pour lire hors ligne
http://www.tutorialspoint.com/matlab/matlab_integ ration.htm Copyright © tutorialspoint.com
MATLAB - INTEGRATION
Integrationdeals withtwo essentially different types of problems.
Inthe first type, derivative of a functionis givenand we want to find the function. Therefore, we basically
reverse the process of differentiation. This reverse process is knownas anti-differentiation, or finding the
primitive function, or finding anindefinite integral.
The second type of problems involve adding up a very large number of very smallquantities and then
taking a limit as the size of the quantities approaches zero, while the number of terms tend to infinity. This
process leads to the definitionof the definite integral.
Definite integrals are used for finding area, volume, center of gravity, moment of inertia, work done by a force,
and innumerous other applications.
Finding Indefinite Integral Using MATLAB
By definition, if the derivative of a functionf(x) is f'(x), thenwe say that anindefinite integralof f'(x) withrespect to
x is f(x). For example, since the derivative (withrespect to x) of x2 is 2x, we cansay that anindefinite integralof
2x is x2.
Insymbols:
f'(x2) = 2x, therefore,
∫ 2xdx = x2.
Indefinite integralis not unique, because derivative of x2 + c, for any value of a constant c, willalso be 2x.
This is expressed insymbols as:
∫ 2xdx = x2 + c.
Where, c is called an'arbitrary constant'.
MATLAB provides anint command for calculating integralof anexpression. To derive anexpressionfor the
indefinite integralof a function, we write:
int(f);
For example, fromour previous example:
syms x
int(2*x)
MATLAB executes the above statement and returns the following result:
ans =
x^2
Example 1
Inthis example, let us find the integralof some commonly used expressions. Create a script file and type the
following code init:
syms x n
int(sym(x^n))
f = 'sin(n*t)'
int(sym(f))
syms a t
int(a*cos(pi*t))
int(a^x)
Whenyourunthe file, it displays the following result:
ans =
piecewise([n == -1, log(x)], [n ~= -1, x^(n + 1)/(n + 1)])
f =
sin(n*t)
ans =
-cos(n*t)/n
ans =
(a*sin(pi*t))/pi
ans =
a^x/log(a)
Example 2
Create a script file and type the following code init:
syms x n
int(cos(x))
int(exp(x))
int(log(x))
int(x^-1)
int(x^5*cos(5*x))
pretty(int(x^5*cos(5*x)))
int(x^-5)
int(sec(x)^2)
pretty(int(1 - 10*x + 9 * x^2))
int((3 + 5*x -6*x^2 - 7*x^3)/2*x^2)
pretty(int((3 + 5*x -6*x^2 - 7*x^3)/2*x^2))
Note that the pretty command returns anexpressionina more readable format.
Whenyourunthe file, it displays the following result:
ans =
sin(x)
ans =
exp(x)
ans =
x*(log(x) - 1)
ans =
log(x)
ans =
(24*cos(5*x))/3125 + (24*x*sin(5*x))/625 - (12*x^2*cos(5*x))/125 + (x^4*cos(5*x))/5 -
(4*x^3*sin(5*x))/25 + (x^5*sin(5*x))/5
2 4
24 cos(5 x) 24 x sin(5 x) 12 x cos(5 x) x cos(5 x)
----------- + ------------- - -------------- + ----------- -
3125 625 125 5
3 5
4 x sin(5 x) x sin(5 x)
------------- + -----------
25 5
ans =
-1/(4*x^4)
ans =
tan(x)
2
x (3 x - 5 x + 1)
ans =
- (7*x^6)/12 - (3*x^5)/5 + (5*x^4)/8 + x^3/2
6 5 4 3
7 x 3 x 5 x x
- ---- - ---- + ---- + --
12 5 8 2
Finding Definite Integral Using MATLAB
By definition, definite integralis basically the limit of a sum. We use definite integrals to find areas suchas the area
betweena curve and the x-axis and the area betweentwo curves. Definite integrals canalso be used inother
situations, where the quantity required canbe expressed as the limit of a sum.
The int command canbe used for definite integrationby passing the limits over whichyouwant to calculate the
integral.
To calculate
we write,
int(x, a, b)
For example, to calculate the value of we write:
int(x, 4, 9)
MATLAB executes the above statement and returns the following result:
ans =
65/2
Following is Octave equivalent of the above calculation:
pkg load symbolic
symbols
x = sym("x");
f = x;
c = [1, 0];
integral = polyint(c);
a = polyval(integral, 9) - polyval(integral, 4);
display('Area: '), disp(double(a));
Analternative solutioncanbe givenusing quad() functionprovided by Octave as follows:
pkg load symbolic
symbols
f = inline("x");
[a, ierror, nfneval] = quad(f, 4, 9);
display('Area: '), disp(double(a));
Example 1
Let us calculate the area enclosed betweenthe x-axis, and the curve y = x3−2x+5 and the ordinates x = 1 and x =
2.
The required area is givenby:
Create a script file and type the following code:
f = x^3 - 2*x +5;
a = int(f, 1, 2)
display('Area: '), disp(double(a));
Whenyourunthe file, it displays the following result:
a =
23/4
Area:
5.7500
Following is Octave equivalent of the above calculation:
pkg load symbolic
symbols
x = sym("x");
f = x^3 - 2*x +5;
c = [1, 0, -2, 5];
integral = polyint(c);
a = polyval(integral, 2) - polyval(integral, 1);
display('Area: '), disp(double(a));
Analternative solutioncanbe givenusing quad() functionprovided by Octave as follows:
pkg load symbolic
symbols
x = sym("x");
f = inline("x^3 - 2*x +5");
[a, ierror, nfneval] = quad(f, 1, 2);
display('Area: '), disp(double(a));
Example 2
Find the area under the curve: f(x) = x2 cos(x) for −4 ≤ x ≤ 9.
Create a script file and write the following code:
f = x^2*cos(x);
ezplot(f, [-4,9])
a = int(f, -4, 9)
disp('Area: '), disp(double(a));
Whenyourunthe file, MATLAB plots the graph:
and displays the following result:
a =
8*cos(4) + 18*cos(9) + 14*sin(4) + 79*sin(9)
Area:
0.3326
Following is Octave equivalent of the above calculation:
pkg load symbolic
symbols
x = sym("x");
f = inline("x^2*cos(x)");
ezplot(f, [-4,9])
print -deps graph.eps
[a, ierror, nfneval] = quad(f, -4, 9);
display('Area: '), disp(double(a));

Contenu connexe

Tendances

Daniel Hong ENGR 019 Q6
Daniel Hong ENGR 019 Q6Daniel Hong ENGR 019 Q6
Daniel Hong ENGR 019 Q6
Daniel Hong
 

Tendances (20)

How to make boxed text with LaTeX
How to make boxed text with LaTeXHow to make boxed text with LaTeX
How to make boxed text with LaTeX
 
Python programming : Control statements
Python programming : Control statementsPython programming : Control statements
Python programming : Control statements
 
Newton divided difference interpolation
Newton divided difference interpolationNewton divided difference interpolation
Newton divided difference interpolation
 
Python programming: Anonymous functions, String operations
Python programming: Anonymous functions, String operationsPython programming: Anonymous functions, String operations
Python programming: Anonymous functions, String operations
 
Interpolation with Finite differences
Interpolation with Finite differencesInterpolation with Finite differences
Interpolation with Finite differences
 
Jacobi method for MATLAB
Jacobi method for MATLAB Jacobi method for MATLAB
Jacobi method for MATLAB
 
Techniques of Integration ppt.ppt
Techniques of Integration ppt.pptTechniques of Integration ppt.ppt
Techniques of Integration ppt.ppt
 
trapezoidal and simpson's 1/3 and 3/8 rule
trapezoidal and simpson's 1/3 and 3/8 ruletrapezoidal and simpson's 1/3 and 3/8 rule
trapezoidal and simpson's 1/3 and 3/8 rule
 
newton raphson method
newton raphson methodnewton raphson method
newton raphson method
 
Access modifiers in Python
Access modifiers in PythonAccess modifiers in Python
Access modifiers in Python
 
Functions
FunctionsFunctions
Functions
 
Python: Multiple Inheritance
Python: Multiple InheritancePython: Multiple Inheritance
Python: Multiple Inheritance
 
Jacobi method
Jacobi methodJacobi method
Jacobi method
 
Introduction to MATLAB
Introduction to MATLABIntroduction to MATLAB
Introduction to MATLAB
 
Daniel Hong ENGR 019 Q6
Daniel Hong ENGR 019 Q6Daniel Hong ENGR 019 Q6
Daniel Hong ENGR 019 Q6
 
Regula falsi MATLAB Code
Regula falsi MATLAB CodeRegula falsi MATLAB Code
Regula falsi MATLAB Code
 
Linear dependence & independence vectors
Linear dependence & independence vectorsLinear dependence & independence vectors
Linear dependence & independence vectors
 
Independence, basis and dimension
Independence, basis and dimensionIndependence, basis and dimension
Independence, basis and dimension
 
Multilayer & Back propagation algorithm
Multilayer & Back propagation algorithmMultilayer & Back propagation algorithm
Multilayer & Back propagation algorithm
 
neural networksNnf
neural networksNnfneural networksNnf
neural networksNnf
 

Similaire à Matlab integration

High-Performance Haskell
High-Performance HaskellHigh-Performance Haskell
High-Performance Haskell
Johan Tibell
 
Learn a language : LISP
Learn a language : LISPLearn a language : LISP
Learn a language : LISP
Devnology
 
error 2.pdf101316, 6(46 PM01_errorPage 1 of 5http.docx
error 2.pdf101316, 6(46 PM01_errorPage 1 of 5http.docxerror 2.pdf101316, 6(46 PM01_errorPage 1 of 5http.docx
error 2.pdf101316, 6(46 PM01_errorPage 1 of 5http.docx
SALU18
 
Столпы функционального программирования для адептов ООП, Николай Мозговой
Столпы функционального программирования для адептов ООП, Николай МозговойСтолпы функционального программирования для адептов ООП, Николай Мозговой
Столпы функционального программирования для адептов ООП, Николай Мозговой
Sigma Software
 

Similaire à Matlab integration (20)

Matlab differential
Matlab differentialMatlab differential
Matlab differential
 
III MCS python lab (1).pdf
III MCS python lab (1).pdfIII MCS python lab (1).pdf
III MCS python lab (1).pdf
 
Matlab algebra
Matlab algebraMatlab algebra
Matlab algebra
 
Matlab functions
Matlab functionsMatlab functions
Matlab functions
 
High-Performance Haskell
High-Performance HaskellHigh-Performance Haskell
High-Performance Haskell
 
Matlab plotting
Matlab plottingMatlab plotting
Matlab plotting
 
C sharp chap6
C sharp chap6C sharp chap6
C sharp chap6
 
Learn a language : LISP
Learn a language : LISPLearn a language : LISP
Learn a language : LISP
 
error 2.pdf101316, 6(46 PM01_errorPage 1 of 5http.docx
error 2.pdf101316, 6(46 PM01_errorPage 1 of 5http.docxerror 2.pdf101316, 6(46 PM01_errorPage 1 of 5http.docx
error 2.pdf101316, 6(46 PM01_errorPage 1 of 5http.docx
 
Matlab1
Matlab1Matlab1
Matlab1
 
Столпы функционального программирования для адептов ООП, Николай Мозговой
Столпы функционального программирования для адептов ООП, Николай МозговойСтолпы функционального программирования для адептов ООП, Николай Мозговой
Столпы функционального программирования для адептов ООП, Николай Мозговой
 
Chapter 02 functions -class xii
Chapter 02   functions -class xiiChapter 02   functions -class xii
Chapter 02 functions -class xii
 
Tutorial2
Tutorial2Tutorial2
Tutorial2
 
Pydiomatic
PydiomaticPydiomatic
Pydiomatic
 
Python idiomatico
Python idiomaticoPython idiomatico
Python idiomatico
 
Loops in Python
Loops in PythonLoops in Python
Loops in Python
 
Subtle Asynchrony by Jeff Hammond
Subtle Asynchrony by Jeff HammondSubtle Asynchrony by Jeff Hammond
Subtle Asynchrony by Jeff Hammond
 
ForLoopandUserDefinedFunctions.pptx
ForLoopandUserDefinedFunctions.pptxForLoopandUserDefinedFunctions.pptx
ForLoopandUserDefinedFunctions.pptx
 
Problem solving using computers - Chapter 1
Problem solving using computers - Chapter 1 Problem solving using computers - Chapter 1
Problem solving using computers - Chapter 1
 
Tutorial 2
Tutorial     2Tutorial     2
Tutorial 2
 

Plus de pramodkumar1804 (20)

Matlab syntax
Matlab syntaxMatlab syntax
Matlab syntax
 
Matlab strings
Matlab stringsMatlab strings
Matlab strings
 
Matlab simulink
Matlab simulinkMatlab simulink
Matlab simulink
 
Matlab polynomials
Matlab polynomialsMatlab polynomials
Matlab polynomials
 
Matlab overview 3
Matlab overview 3Matlab overview 3
Matlab overview 3
 
Matlab overview 2
Matlab overview 2Matlab overview 2
Matlab overview 2
 
Matlab overview
Matlab overviewMatlab overview
Matlab overview
 
Matlab operators
Matlab operatorsMatlab operators
Matlab operators
 
Matlab variables
Matlab variablesMatlab variables
Matlab variables
 
Matlab numbers
Matlab numbersMatlab numbers
Matlab numbers
 
Matlab matrics
Matlab matricsMatlab matrics
Matlab matrics
 
Matlab m files
Matlab m filesMatlab m files
Matlab m files
 
Matlab loops 2
Matlab loops 2Matlab loops 2
Matlab loops 2
 
Matlab loops
Matlab loopsMatlab loops
Matlab loops
 
Matlab graphics
Matlab graphicsMatlab graphics
Matlab graphics
 
Matlab gnu octave
Matlab gnu octaveMatlab gnu octave
Matlab gnu octave
 
Matlab operators
Matlab operatorsMatlab operators
Matlab operators
 
Matlab decisions
Matlab decisionsMatlab decisions
Matlab decisions
 
Matlab data import
Matlab data importMatlab data import
Matlab data import
 
Matlab colon notation
Matlab colon notationMatlab colon notation
Matlab colon notation
 

Dernier

Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
Chris Hunter
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 

Dernier (20)

INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Role Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptxRole Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptx
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 

Matlab integration

  • 1. http://www.tutorialspoint.com/matlab/matlab_integ ration.htm Copyright © tutorialspoint.com MATLAB - INTEGRATION Integrationdeals withtwo essentially different types of problems. Inthe first type, derivative of a functionis givenand we want to find the function. Therefore, we basically reverse the process of differentiation. This reverse process is knownas anti-differentiation, or finding the primitive function, or finding anindefinite integral. The second type of problems involve adding up a very large number of very smallquantities and then taking a limit as the size of the quantities approaches zero, while the number of terms tend to infinity. This process leads to the definitionof the definite integral. Definite integrals are used for finding area, volume, center of gravity, moment of inertia, work done by a force, and innumerous other applications. Finding Indefinite Integral Using MATLAB By definition, if the derivative of a functionf(x) is f'(x), thenwe say that anindefinite integralof f'(x) withrespect to x is f(x). For example, since the derivative (withrespect to x) of x2 is 2x, we cansay that anindefinite integralof 2x is x2. Insymbols: f'(x2) = 2x, therefore, ∫ 2xdx = x2. Indefinite integralis not unique, because derivative of x2 + c, for any value of a constant c, willalso be 2x. This is expressed insymbols as: ∫ 2xdx = x2 + c. Where, c is called an'arbitrary constant'. MATLAB provides anint command for calculating integralof anexpression. To derive anexpressionfor the indefinite integralof a function, we write: int(f); For example, fromour previous example: syms x int(2*x) MATLAB executes the above statement and returns the following result: ans = x^2 Example 1 Inthis example, let us find the integralof some commonly used expressions. Create a script file and type the following code init: syms x n int(sym(x^n)) f = 'sin(n*t)' int(sym(f)) syms a t
  • 2. int(a*cos(pi*t)) int(a^x) Whenyourunthe file, it displays the following result: ans = piecewise([n == -1, log(x)], [n ~= -1, x^(n + 1)/(n + 1)]) f = sin(n*t) ans = -cos(n*t)/n ans = (a*sin(pi*t))/pi ans = a^x/log(a) Example 2 Create a script file and type the following code init: syms x n int(cos(x)) int(exp(x)) int(log(x)) int(x^-1) int(x^5*cos(5*x)) pretty(int(x^5*cos(5*x))) int(x^-5) int(sec(x)^2) pretty(int(1 - 10*x + 9 * x^2)) int((3 + 5*x -6*x^2 - 7*x^3)/2*x^2) pretty(int((3 + 5*x -6*x^2 - 7*x^3)/2*x^2)) Note that the pretty command returns anexpressionina more readable format. Whenyourunthe file, it displays the following result: ans = sin(x) ans = exp(x) ans = x*(log(x) - 1) ans = log(x) ans = (24*cos(5*x))/3125 + (24*x*sin(5*x))/625 - (12*x^2*cos(5*x))/125 + (x^4*cos(5*x))/5 - (4*x^3*sin(5*x))/25 + (x^5*sin(5*x))/5 2 4 24 cos(5 x) 24 x sin(5 x) 12 x cos(5 x) x cos(5 x) ----------- + ------------- - -------------- + ----------- - 3125 625 125 5 3 5
  • 3. 4 x sin(5 x) x sin(5 x) ------------- + ----------- 25 5 ans = -1/(4*x^4) ans = tan(x) 2 x (3 x - 5 x + 1) ans = - (7*x^6)/12 - (3*x^5)/5 + (5*x^4)/8 + x^3/2 6 5 4 3 7 x 3 x 5 x x - ---- - ---- + ---- + -- 12 5 8 2 Finding Definite Integral Using MATLAB By definition, definite integralis basically the limit of a sum. We use definite integrals to find areas suchas the area betweena curve and the x-axis and the area betweentwo curves. Definite integrals canalso be used inother situations, where the quantity required canbe expressed as the limit of a sum. The int command canbe used for definite integrationby passing the limits over whichyouwant to calculate the integral. To calculate we write, int(x, a, b) For example, to calculate the value of we write: int(x, 4, 9) MATLAB executes the above statement and returns the following result: ans = 65/2 Following is Octave equivalent of the above calculation: pkg load symbolic symbols x = sym("x");
  • 4. f = x; c = [1, 0]; integral = polyint(c); a = polyval(integral, 9) - polyval(integral, 4); display('Area: '), disp(double(a)); Analternative solutioncanbe givenusing quad() functionprovided by Octave as follows: pkg load symbolic symbols f = inline("x"); [a, ierror, nfneval] = quad(f, 4, 9); display('Area: '), disp(double(a)); Example 1 Let us calculate the area enclosed betweenthe x-axis, and the curve y = x3−2x+5 and the ordinates x = 1 and x = 2. The required area is givenby: Create a script file and type the following code: f = x^3 - 2*x +5; a = int(f, 1, 2) display('Area: '), disp(double(a)); Whenyourunthe file, it displays the following result: a = 23/4 Area: 5.7500 Following is Octave equivalent of the above calculation: pkg load symbolic symbols x = sym("x"); f = x^3 - 2*x +5; c = [1, 0, -2, 5]; integral = polyint(c); a = polyval(integral, 2) - polyval(integral, 1); display('Area: '), disp(double(a)); Analternative solutioncanbe givenusing quad() functionprovided by Octave as follows: pkg load symbolic symbols
  • 5. x = sym("x"); f = inline("x^3 - 2*x +5"); [a, ierror, nfneval] = quad(f, 1, 2); display('Area: '), disp(double(a)); Example 2 Find the area under the curve: f(x) = x2 cos(x) for −4 ≤ x ≤ 9. Create a script file and write the following code: f = x^2*cos(x); ezplot(f, [-4,9]) a = int(f, -4, 9) disp('Area: '), disp(double(a)); Whenyourunthe file, MATLAB plots the graph: and displays the following result: a = 8*cos(4) + 18*cos(9) + 14*sin(4) + 79*sin(9) Area: 0.3326 Following is Octave equivalent of the above calculation: pkg load symbolic symbols x = sym("x"); f = inline("x^2*cos(x)"); ezplot(f, [-4,9]) print -deps graph.eps [a, ierror, nfneval] = quad(f, -4, 9);