Sunteți pe pagina 1din 154

Chapter 3

Computer Solutions
to Calculus Problems
Scientific Computing with
MATLAB, 2nd Edition
CRC/Taylor & Francis Press
Chinese version by Tsinghua University Press

PPT by Wenbin Dong and Jun Peng, Northeastern University, PRC


Proofread by Dingyu Xue & YangQuan Chen
5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 1/154
with MATLAB, 2nd Edition. CRC Press, 2016
Computer Solutions
Chapter 3
to Calculus Problems
□ A new view-point to the calculus course
Analytical solutions to limit problems
Analytical solutions to differential problems
Analytical solutions to integral problems
Series expansion and sum/product of series
Curve integral and surface integral
Numerical differentiations and integrations
5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 2/154
with MATLAB, 2nd Edition. CRC Press, 2016
3.1 Analytical Solutions of
Limit Problems
□ The concept of limit is given
 Concentrations are made on how to find limits
 In traditional calculus course, lots of practice are
required to learn skills, while with MATLAB, regular
functions can be called directly
□ Main topics in the section
 Limit of single variable functions
 Limit of interval functions
 Limits of multivariable functions
5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 3/154
with MATLAB, 2nd Edition. CRC Press, 2016
3.1.1 Limit of Single
Variable Functions
□ Definition of limit
□ MATLAB function

□ Left or right limits

□ MATLAB function

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 4/154


with MATLAB, 2nd Edition. CRC Press, 2016
Example 3.1 A Simple
Limit Problem
□ Please solve limit

□ MATLAB commands

□ Three-stages
Declare variables describe function solve
No intermediate results, no skills needed
5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 5/154
with MATLAB, 2nd Edition. CRC Press, 2016
Example 3.2 Single-sided
Limit Problem Solution
□ Solve the problem

□ MATLAB statements

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 6/154


with MATLAB, 2nd Edition. CRC Press, 2016
Extended Knowledge
□ Plotting with MATLAB

□ Extension: cosine of imaginary number


Euler formula
□ Taking limit directly

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 7/154


with MATLAB, 2nd Edition. CRC Press, 2016
Example 3.3 One-sided Limits
of Tangent Function
□ Function tan t
Left and right limits around p/2

□ MATLAB commands

□ Break point
5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 8/154
with MATLAB, 2nd Edition. CRC Press, 2016
Example 3-4 Limit of a
Sequence
□ Given the sequence

□ Sequence limit can be treated the same


Declare variables, describe sequence, call limit()

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 9/154


with MATLAB, 2nd Edition. CRC Press, 2016
Example 3-5 Limit of a
Sequence of a Function
□ Both function or sequence

□ Solve in the same way – three-stages

□ No difference in solution for the user


5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 10/154
with MATLAB, 2nd Edition. CRC Press, 2016
3.1.2 Limit of
Interval Functions
□ Example 3-6: Limits
□ Cannot be solved with earlier MATLAB
□ In new version

□ Piecewise functions are supported


5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 11/154
with MATLAB, 2nd Edition. CRC Press, 2016
Low-level limit function
in MuPAD
□ Use low-level limit function

□ Example 3-7:
Find

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 12/154


with MATLAB, 2nd Edition. CRC Press, 2016
Piecewise Function
Descriptions
□ An interface to MuPAD

□ Syntax
5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 13/154
with MATLAB, 2nd Edition. CRC Press, 2016
Example 3-8 Plotting of
Piecewise Functions
□ Piecewise function

□ MATLAB symbolic description


5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 14/154
with MATLAB, 2nd Edition. CRC Press, 2016
3.1.3 Limit of
Multivariable Functions
□ Sequential limit of f (x,y)

□ Solution in MATLAB

□ Pay attention to the orders


5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 15/154
with MATLAB, 2nd Edition. CRC Press, 2016
Example 3.9 Sequential Limit
□ Find the limit

□ MATLAB commands
Three-phase solution

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 16/154


with MATLAB, 2nd Edition. CRC Press, 2016
Multiple Limits
□ Math expression

□ Difficulties in solutions
Along all directions
At all speed in different directions
Special cases
Different sequential limit, no multiple limit
Same sequential limit, no multiple limit

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 17/154


with MATLAB, 2nd Edition. CRC Press, 2016
Example 3-10 Multiple Limit
□ Problem

□ Solutions
Try 4 different directions and speeds

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 18/154


with MATLAB, 2nd Edition. CRC Press, 2016
3.2 Derivatives of Functions
□ Mathematical form of derivatives
□ Various derivatives with MATLAB
Derivatives and high-order derivatives
Partial derivatives of functions
Jacobian matrix
Hessian matrix
Derivatives of implicit functions
Derivatives of parametric equatoins

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 19/154


with MATLAB, 2nd Edition. CRC Press, 2016
3.2.1 Derivatives and
High-order Derivatives
□ Three-phases
Declare symbolic variables
Function expression in MATLAB
Call diff()function to solve problem
□ Syntaxes
or
If the only symbolic variable, omit it
5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 20/154
with MATLAB, 2nd Edition. CRC Press, 2016
Example 3.11 Derivatives and
Their Plots
□ Given function
□ Find

□ Find 1st order derivative with MATLAB

□ Plot original function and 1st order derivative

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 21/154


with MATLAB, 2nd Edition. CRC Press, 2016
4th and Even Higher
Order Derivative
□ 4th order derivative

□ Simplification

□ High efficiency of function diff()

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 22/154


with MATLAB, 2nd Edition. CRC Press, 2016
Example 3.12 Derivative of
Complicated Functions
□ Known
□ Find 3rd order derivative
Difficulty: how to define f(t)
MATLAB solutions

□ When find 3rd order derivative

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 23/154


with MATLAB, 2nd Edition. CRC Press, 2016
Example 3-13 Derivatives
of a Matrix
□ Given matrix

□ Find directly the derivative


Direct derivative to each element in matrix

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 24/154


with MATLAB, 2nd Edition. CRC Press, 2016
3.2.2 Derivatives of
Parametric Equations
□ Parametric equations
□ Evaluate recursively

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 25/154


with MATLAB, 2nd Edition. CRC Press, 2016
Recursive Implementation
□ Derivative of parametric equations

□ Syntax (n is a specific positive integer)

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 26/154


with MATLAB, 2nd Edition. CRC Press, 2016
Example 3.14 Derivative
of Parametric Equation
□ Given equations
□ Find

□ MATLAB commands

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 27/154


with MATLAB, 2nd Edition. CRC Press, 2016
3.2.3 Partial Derivatives of
Multivariable Functions
□ Function with 2 independent variables f(x,y)
□ Find high-order derivatives

□ MATLAB syntax

□ or
5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 28/154
with MATLAB, 2nd Edition. CRC Press, 2016
Example 3.15 Gradients
□ Given 2-variable function

□ Two 1st order derivatives

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 29/154


with MATLAB, 2nd Edition. CRC Press, 2016
Graphical Interpretation
of Gradients
□ 3D surface

□ Attractions (negative gradients)

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 30/154


with MATLAB, 2nd Edition. CRC Press, 2016
Example 3.16 Partial Derivatives

□ Function
□ Partial derivatives

□ MATLAB solutions

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 31/154


with MATLAB, 2nd Edition. CRC Press, 2016
3.2.4 Partial Derivatives
of Implicit Functions
□ Implicit functions

□ 1sr order derivative

□ MATLAB command

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 32/154


with MATLAB, 2nd Edition. CRC Press, 2016
High-order Partial Derivatives
□ Given function f (x,y)
□ 1st order derivative
□ 2nd order

□ High-order

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 33/154


with MATLAB, 2nd Edition. CRC Press, 2016
MATLAB Implementation
□ Iterative formula

□ MATLAB solutions

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 34/154


with MATLAB, 2nd Edition. CRC Press, 2016
Ex 3.17 Derivatives of
Implicit Function
□ Implicit function

1st order partial derivative

2nd and 3rd order

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 35/154


with MATLAB, 2nd Edition. CRC Press, 2016
Example 3-18 Derivative and
Simplification of Implicit Functions
□ Implicit function
□ Derivatives

□ Sometimes manual simplification needed

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 36/154


with MATLAB, 2nd Edition. CRC Press, 2016
3.2.5 Jacobian Matrix
□ Function

□ Jacobian matrix

□ MATLAB solutions
5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 37/154
with MATLAB, 2nd Edition. CRC Press, 2016
Example 3.19 Finding the
Jacobian Matrix
□ Descartes to polar coordinate conversion

□ Find the Jacobian matrix

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 38/154


with MATLAB, 2nd Edition. CRC Press, 2016
3.2.6 Hessian Matrix
□ Scalar function
□ Hessian matrix

□ MATLAB solution
□ Earlier versions
5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 39/154
with MATLAB, 2nd Edition. CRC Press, 2016
Example 3.20 Hessian Matrix
□ Function with 2 independent variables

□ MATLAB solution

□ Alternatively

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 40/154


with MATLAB, 2nd Edition. CRC Press, 2016
3.3 Analytical Solutions to
Integral Problems
□ Inverse process of differentiation
□ A lot of methods and skills should be learnt
Integration by parts, variable substitution
□ No skills necessary with use MATLAB
Indefinite integrals
Definite and infinite integrals
Multiple integral problems solutions
5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 41/154
with MATLAB, 2nd Edition. CRC Press, 2016
3.3.1 Indefinite Integrals
□ Indefinite integrals

□ MATLAB solutions
integral
Multiple integrals, nested use or loops

Primitive function returned, should add C


5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 42/154
with MATLAB, 2nd Edition. CRC Press, 2016
Example 3.21 Differentiation
Then Integral to Restore
□ Function
□ First order derivative then integral

□ 4th order derivative then integral

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 43/154


with MATLAB, 2nd Edition. CRC Press, 2016
Example 3.22 Proofs
□ Please show that

□ Simplify the left hand side

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 44/154


with MATLAB, 2nd Edition. CRC Press, 2016
Compare Two Expressions
□ Right hand, then simplification

□ Hints: To show an equation, best way is to


enter both side in MATLAB, then simplify
the difference
□ The error is a constant, to classify to C
5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 45/154
with MATLAB, 2nd Edition. CRC Press, 2016
Example 3.23 Cannot be
integrated, without solution
□ Two functions

□ MATLAB solution

□ Results
□ Special function
5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 46/154
with MATLAB, 2nd Edition. CRC Press, 2016
Non-integratible function
with parameters
□ Find , where
□ MATLAB commands

□ Error message: Warning:Explicit integral


could not be found
□ Some functions do not have primitives
5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 47/154
with MATLAB, 2nd Edition. CRC Press, 2016
3.3.2 Definite Integrals and
Infinite Integrals
□ Definite and infinite integrals

□ MATLAB solutions

□ For primitive F(x), an equation

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 48/154


with MATLAB, 2nd Edition. CRC Press, 2016
Example 3.24 Definite Integrals
□ Function
□ Find integrals for a=0, b=1.5 and ∞
□ MATLAB solutions
In analytical solution exists, display it
Otherwise, return high-precision results

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 49/154


with MATLAB, 2nd Edition. CRC Press, 2016
Example 3.25 Primitive Functions
may be Needed Sometimes
□ Solve

□ MATLAB solutions

□ Take indefinite integral then evaluate

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 50/154


with MATLAB, 2nd Edition. CRC Press, 2016
3.3.3 MATLAB Solutions of
Multiple Integrals
□ Multiple integrals

□ Use function int() directly


□ Note: In some examples, the sequential
order of integrals may affect the final results

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 51/154


with MATLAB, 2nd Edition. CRC Press, 2016
Example 3.26 Triple Integral

□ The function

□ Please evaluate

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 52/154


with MATLAB, 2nd Edition. CRC Press, 2016
Different Sequential Order

□ Different results in old versions


5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 53/154
with MATLAB, 2nd Edition. CRC Press, 2016
Example 3.27 Multiple Integrals

□ Solve with
□ MATLAB solutions

□ Note: eulergamma is Euler constant g

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 54/154


with MATLAB, 2nd Edition. CRC Press, 2016
3.4 Series Expansion of
Functions and Series Sums
□ Taylor series expansion
Taylor series expansion of functions
Taylor series of multivariable functions
□ Fourier series expansion
□ Sum of series
□ Products of sequences
5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 55/154
with MATLAB, 2nd Edition. CRC Press, 2016
3.4.1 Taylor Series Expansion
of Single Variable Functions
□ Mathematical expression
Around x=0, Taylor series expansion

with

□ MATLAB
□ Old versions
5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 56/154
with MATLAB, 2nd Edition. CRC Press, 2016
Taylor Series About x=a Point
□ About x = a, Taylor series expansion

□ where
□ MATLAB

□ Old versions
5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 57/154
with MATLAB, 2nd Edition. CRC Press, 2016
Example 3.28 Taylor Series
□ Function
□ About x=0, x=2 and x=a
About x=0, Taylor series

About x=2, Taylor series

About x = a, Taylor series

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 58/154


with MATLAB, 2nd Edition. CRC Press, 2016
Quality of Approximations
□ Find approximation quality with finite terms
Plot in the interval [-1,1]

Smaller interval [-0.6,0.6]

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 59/154


with MATLAB, 2nd Edition. CRC Press, 2016
Taylor Series of
Multivariable Functions
□ Multivariable
□ Taylor series expansion

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 60/154


with MATLAB, 2nd Edition. CRC Press, 2016
Example 3.30 Taylor Series
Expansion of 2-Variable Functions
□ Function
□ Taylor series around origin

□ About (1,a) point

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 61/154


with MATLAB, 2nd Edition. CRC Press, 2016
3.4.2 Fourier Series Expansion
□ Periodic fun
satisfy
interval (a,b), variable substitution
□ Fourier series expansion

coefficients

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 62/154


with MATLAB, 2nd Edition. CRC Press, 2016
MATLAB Implementation:
Fourier Series
□ Solve
□ MATLAB code for Fourier series

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 63/154


with MATLAB, 2nd Edition. CRC Press, 2016
Supporting Function
□ Assign default values

□ Can be used in other functions


□ Common functions to use
5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 64/154
with MATLAB, 2nd Edition. CRC Press, 2016
Example 3.31 Fourier
Approximation of Functions
□ Function
where
□ Find Fourier series expansion

□ Validate results

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 65/154


with MATLAB, 2nd Edition. CRC Press, 2016
Fitting Quality
□ A larger range

□ Math description

□ General form
5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 66/154
with MATLAB, 2nd Edition. CRC Press, 2016
Example 3.32 Approximation
of Piecewise Functions
□ Function
□ Approximation

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 67/154


with MATLAB, 2nd Edition. CRC Press, 2016
Fitting Expansions
□ First 14 terms

□ Mathematical form

□ General form
5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 68/154
with MATLAB, 2nd Edition. CRC Press, 2016
Assumptions of
Piecewise Functions
□ In interval [-2p,2p], fitting quality comparison

□ The previous assumptions


5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 69/154
with MATLAB, 2nd Edition. CRC Press, 2016
3.4.3 Sums of a Series
□ Sum of finite and infinite retms
□ Mathematical formula
General term

□ MATLAB statement

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 70/154


with MATLAB, 2nd Edition. CRC Press, 2016
Example 3.33 Series Sum
Originated from an Old Legend
□ Solve

□ Numerical solution

□ Use symsum()

□ Expansion with more terms

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 71/154


with MATLAB, 2nd Edition. CRC Press, 2016
Example 3.34 Series Sum
□ Sum of infinite series

□ Use function symsum()

□ With numerical method

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 72/154


with MATLAB, 2nd Edition. CRC Press, 2016
Example 3.35 Sum of Sequence
of a function
□ Compute infinite sequence with x

□ Symbolic computation
Convergent intervals returned

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 73/154


with MATLAB, 2nd Edition. CRC Press, 2016
Example 3.36 A Complicated
Problem
□ Find sum then limit

□ MATLAB solutions

□ Note: finite sum should be evaluated first, not the


infinite sum
5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 74/154
with MATLAB, 2nd Edition. CRC Press, 2016
Example 3.37 Limit of the
Sum of a Series
□ Problem

□ Extraction of general term

□ Solution

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 75/154


with MATLAB, 2nd Edition. CRC Press, 2016
3.4.4 Product of Series
□ Product of series

□ MATLAB statements
New Math Toolbox

Old versions

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 76/154


with MATLAB, 2nd Edition. CRC Press, 2016
Example 3.38 Product of
a Series
□ Compute

□ MATLAB function for finite/infinite series

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 77/154


with MATLAB, 2nd Edition. CRC Press, 2016
Example 3.39 Extraction
of Produce of a Sequence
□ Problem

□ General term
□ Solve
5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 78/154
with MATLAB, 2nd Edition. CRC Press, 2016
Example 3.40 Product of
Sequence of a Function
□ Problem

□ Direct solution

□ Piecewise function explanation


5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 79/154
with MATLAB, 2nd Edition. CRC Press, 2016
3.5 Computations of Curve
and Surface Integrals
□ Main subjects in the section
Curve integrals with MATLAB
Surface integrals with MATLAB
□ No existing MATLAB function to use
□ Direct use of MATLAB according to the
formula, easy to follow
5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 80/154
with MATLAB, 2nd Edition. CRC Press, 2016
3.5.1 Curve Integrals
with MATLAB
□ No MATLAB function to use directly
□ Just use the mathematics book formula and
use corresponding MATLAB commands
□ Main topics in the section
Path integrals
Line integrals
5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 81/154
with MATLAB, 2nd Edition. CRC Press, 2016
3.5.1.1 Path Integrals
□ Definition
□ Substitute into f(·)

or
□ Convert to definite integral problem

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 82/154


with MATLAB, 2nd Edition. CRC Press, 2016
Example 3.41 Path Integral
□ Compute , l is spiral line

Formula
□ MATLAB solutions

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 83/154


with MATLAB, 2nd Edition. CRC Press, 2016
Example 3.42 Closed-path
□ Compute

l is encircled by y = x and

□ Draw the path l and integral area

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 84/154


with MATLAB, 2nd Edition. CRC Press, 2016
Direct Solution of
Path Integral
□ Formula

□ Divided into two path integral problems

□ Results
5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 85/154
with MATLAB, 2nd Edition. CRC Press, 2016
3.5.1.2 Line Integrals
□ Line integral

□ where
□ and

□ Converted to

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 86/154


with MATLAB, 2nd Edition. CRC Press, 2016
Example 3.43 Line Integral
□ Compute

With l positive circle, counterclockwise


Parametric
Integral

□ MATLAB solutions

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 87/154


with MATLAB, 2nd Edition. CRC Press, 2016
Example 3.44 Line Integrals
□ Compute
l is parabolic curve
□ Integral

□ MATLAB solutions

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 88/154


with MATLAB, 2nd Edition. CRC Press, 2016
3.5.2 Surface Integrals and
MATLAB Solutions
□ No direct function to use for surface
integral Problems
□ Need to solve problems with math formula
□ Main topics
First type surface integral
Second type surface integral

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 89/154


with MATLAB, 2nd Edition. CRC Press, 2016
3.5.2.1 First Type Surface
Integrals
□ Mathematical representation

□ S is surface
□ Converted to double integral of x-y plane

□ 其中 为积分区域
5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 90/154
with MATLAB, 2nd Edition. CRC Press, 2016
Example 3.45 Surface Integral
□ Compute , S is

□ Formula

□ MATLAB solutions
The last one, integrand is not zero

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 91/154


with MATLAB, 2nd Edition. CRC Press, 2016
Surface Integral of
Parametric Equations
□ Surface of parametric equations

□ Surface integral

where

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 92/154


with MATLAB, 2nd Edition. CRC Press, 2016
Example 3.46 Surface Integral
□ Compute

Surface S

□ MATLAB solutions

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 93/154


with MATLAB, 2nd Edition. CRC Press, 2016
□ continued

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 94/154


with MATLAB, 2nd Edition. CRC Press, 2016
3.5.2.2 Second Type
Surface Integral
□ Mathematic representation

integrand
With

□ Positive surface S+ with z = f(x,y)


5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 95/154
with MATLAB, 2nd Edition. CRC Press, 2016
Conversion to First Type
□ Conversion to first type surface integral

□ where, z = f(x,y) and

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 96/154


with MATLAB, 2nd Edition. CRC Press, 2016
Conversion Formula 1
□ Integral can be written as

□ Surface is given by

with

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 97/154


with MATLAB, 2nd Edition. CRC Press, 2016
Surface Integral Conversion
with

□ Surface integral can be converted with

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 98/154


with MATLAB, 2nd Edition. CRC Press, 2016
Example 3.47 Surface Integral

□ Compute

S is upper side of the surface, positive

□ Parametric equation introduced

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 99/154


with MATLAB, 2nd Edition. CRC Press, 2016
Surface Integral Solutions
□ Convert to double integrals

□ MATLAB solutions

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 100/154


with MATLAB, 2nd Edition. CRC Press, 2016
3.6 Numerical Differentiations
□ Not presented in calculus course, but widely
used in practical applications
Function is unknown, only scattered data
□ Main topics in the section
Numerical differentiation algorithms
Central difference method and implementation
Gradient computations
5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 101/154
with MATLAB, 2nd Edition. CRC Press, 2016
3.6.1 Numerical Differentiations
□ Definition of derivatives

□ Forward difference

□ Backward difference
□ Algorithms
5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 102/154
with MATLAB, 2nd Edition. CRC Press, 2016
Central Difference Algorithms
□ Formula 1
First order differentiation

Denote

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 103/154


with MATLAB, 2nd Edition. CRC Press, 2016
Error Analysis of Algorithm
Taylor series expansion

Algorithm precision

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 104/154


with MATLAB, 2nd Edition. CRC Press, 2016
Central Differentiation
□ High order differentiation

□ Error o(Dt2)
5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 105/154
with MATLAB, 2nd Edition. CRC Press, 2016
High Precistion Algorithms
□ Differentiation

Precision
5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 106/154
with MATLAB, 2nd Edition. CRC Press, 2016
MATLAB Implementation of
Central Differentiation
□ Syntax
□ Function listing

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 107/154


with MATLAB, 2nd Edition. CRC Press, 2016
Example 3.48 Numerical Diff
□ Function
Generate data, find differentiations
Compare with theoretic method
□ Analytical solutions

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 108/154


with MATLAB, 2nd Edition. CRC Press, 2016
Precisions
□ Comparing derivatives of different orders

□ Error analysis

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 109/154


with MATLAB, 2nd Edition. CRC Press, 2016
3.6.3 Gradient Computations
□ Multivariable function f(x1, x2,…, xn)
□ Definitions of gradients

□ Syntax of gradient() function

□ Gradient computation
□ where Dx and Dy are step-sizes in x, y
5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 110/154
with MATLAB, 2nd Edition. CRC Press, 2016
Example 3.49 Gradient
□ Function
Generate data
Calculate gradients and analyze errors
□ MATLAB solutions

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 111/154


with MATLAB, 2nd Edition. CRC Press, 2016
Error Surface
□ Error surface, compared with the theoretical
results

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 112/154


with MATLAB, 2nd Edition. CRC Press, 2016
With Densely Distributed Grids
□ Defining more points

□ Graphics comparisons

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 113/154


with MATLAB, 2nd Edition. CRC Press, 2016
3.7 Numerical Integrals
□ Integrals with numerical approach
Integrals with scattered data
Integrals with known functions
□ Main topics
Integrals with trapezoidal method
Integrals with one variable
Numerical evaluation of infinite integrals
Evaluation of integral functions
2D, 3D and multi-D numerical integrals
5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 114/154
with MATLAB, 2nd Edition. CRC Press, 2016
3.7.1 Trapezoidal Methods in
Scatted Data Integrals
□ Basic idea of trapezoidal method

□ MATLAB syntax

□ or
5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 115/154
with MATLAB, 2nd Edition. CRC Press, 2016
Example 3.50
Integral Evaluations
□ Evaluate functions
□ Definite integral in interval
□ MATLAB solutions

□ Conclusion: large step-size lead to large error


5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 116/154
with MATLAB, 2nd Edition. CRC Press, 2016
Example 3.51 Fixed-step
□ Solve with fixed-step

□ Compare results under different step-size


□ Draw plots

□ Strong oscillation lead to errors

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 117/154


with MATLAB, 2nd Edition. CRC Press, 2016
Comparisons
□ With different step-sizes

5/19/2018 0.25seconds
Dingyü Xue and YangQuan Chen. Scientific Computing 118/154
with MATLAB, 2nd Edition. CRC Press, 2016
3.7.2 Numerical Integral with
One Independent Variable
□ Example of algorithms
Simpson method, integral

where

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 119/154


with MATLAB, 2nd Edition. CRC Press, 2016
Solution with the New Function
□ Syntax
Numerical integral

Old version
Definite integral

Other functions
quadl(), quadgk(), quadv()
5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 120/154
with MATLAB, 2nd Edition. CRC Press, 2016
Example 3.52 MATLAB
Descriptions of Integrand
□ Compute
Method 1, MATLAB function (dot operation)

Method 2, inline function (not recommended)

Method 3, anonymous function

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 121/154


with MATLAB, 2nd Edition. CRC Press, 2016
Numerical Solutions
□ MATLAB solutions

□ Analytical solution with Symbolic Toolbox

□ Under default controls, integral() function may


ensure high-precision results
5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 122/154
with MATLAB, 2nd Edition. CRC Press, 2016
Example 3.53 Integral with
Piecewise Functions
□ The piecewise function

□ Compute integral
□ Graphical illustration

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 123/154


with MATLAB, 2nd Edition. CRC Press, 2016
Solutions and Validations
□ MATLAB solutions

□ Increase the tolerance for validation

□ Analytical solution

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 124/154


with MATLAB, 2nd Edition. CRC Press, 2016
Example 3.54 Comparison with
Trapezoidal Method
□ Compute

□ MATLAB solutions

□ Conclusion: Increase in speed and accuracy


□ Theoretical value: 1/15
5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 125/154
with MATLAB, 2nd Edition. CRC Press, 2016
Example 3.55 Integral of
Complex Functions
□ Complex integral

□ Numerical solution

□ Analytical solution

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 126/154


with MATLAB, 2nd Edition. CRC Press, 2016
Example3.56 Integral of
Larger Interval
□ Compute

□ Integral functions in old versions not work


□ Numerical solutions

□ Analytical solutions

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 127/154


with MATLAB, 2nd Edition. CRC Press, 2016
3.7.3 Solutions of Infinite
Integral Problems
□ Integral() can be used to evaluate directly
infinite integral problems
□ With the same syntax

In old versions, the Gauss-Kronrod algorithm is


used, with function

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 128/154


with MATLAB, 2nd Edition. CRC Press, 2016
Example 3.57 Infinite Integral
□ Compute

□ Numerical and analytical solutions


No analytical solution, special function erf()
Numerical solutions can be obtained

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 129/154


with MATLAB, 2nd Edition. CRC Press, 2016
Example 3.58 Integrals of
Functions with Other Parameters
□ Integral function I(a), draw the curve vs a

□ Vector parameter a supported in new version

□ Loop for a is needed in old versions


5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 130/154
with MATLAB, 2nd Edition. CRC Press, 2016
3.7.4 Evaluations of
Integral Functions
□ Definite integral was calculated
□ How to find integral functions?
□ MATLAB function is written

□ Syntax
5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 131/154
with MATLAB, 2nd Edition. CRC Press, 2016
Example 3.59 Piecewise Function
□ Draw integral function

□ MATLAB solutions

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 132/154


with MATLAB, 2nd Edition. CRC Press, 2016
3.7.5 Numerical Solutions of
Double Integrals
□ Double integrals in rectangular region

□ MATLAB function
Rectangular region

Old versions

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 133/154


with MATLAB, 2nd Edition. CRC Press, 2016
Example 3.60 Double Integral

□ Please evaluate double integral

Rectangular region
□ MATLAB solutions

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 134/154


with MATLAB, 2nd Edition. CRC Press, 2016
Evaluation of Integral Functions
□ MATLAB function

□ Syntax

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 135/154


with MATLAB, 2nd Edition. CRC Press, 2016
Example 3.61 Integral Function

□ Draw integral function surface

□ MATLAB solutions
The last value is definite integral results

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 136/154


with MATLAB, 2nd Edition. CRC Press, 2016
Double Integrals of Non-
rectangular regions
□ Standard mathematical form

□ Order of integral, first y, then x


Solve directly with integral2
New version can solve non-rectangular problems
ym and yM can be function handles

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 137/154


with MATLAB, 2nd Edition. CRC Press, 2016
With Different Orders
□ Integral

Swap the order of x and y in integrand


Let

□ In describing the integrand, use

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 138/154


with MATLAB, 2nd Edition. CRC Press, 2016
Example 3.62 Double Integral
□ Compute double integral

□ First y then x, correct order

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 139/154


with MATLAB, 2nd Edition. CRC Press, 2016
Comparisons with
Analytical Solutions
□ Analytical method – order of integrals

□ Differences in analytical& numerical solutions


Some integrals has no solutions, with vpa, the
solutions cannot be obtained
Numerical solutions treat the problems in the same
way, no matter whether analytical solutions exist
5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 140/154
with MATLAB, 2nd Edition. CRC Press, 2016
Example 3.63 No Analytic
Solutions
□ First x then y, need swapped

□ No analytical solution, numerical only choice


□ Swap the orders of x,y

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 141/154


with MATLAB, 2nd Edition. CRC Press, 2016
Example 3.64 Integral Function
□ Draw integral function of

□ Method: Find integral function over rectangular


region, then set outside values to NaN

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 142/154


with MATLAB, 2nd Edition. CRC Press, 2016
3.7.6 Numeric Triple Integrals
□ Triple integrals with cubic regions

□ Syntaxes

□ Old versions

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 143/154


with MATLAB, 2nd Edition. CRC Press, 2016
Example 3.65 Triple Integral
□ Compute numerically triple integral

Rectangular region
□ MATLAB solutions

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 144/154


with MATLAB, 2nd Edition. CRC Press, 2016
Example 3-66 Non-rectangular
Integral Regions in Triple Integral
□ Triple integral

□ Numerical solutions, integral()

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 145/154


with MATLAB, 2nd Edition. CRC Press, 2016
3.7.7 Numerical Solutions of
Triple Integral Problems
□ NIT Toolbox (Numerical Integral Toolbox)
can be used to compute multiple integrals
Hyper rectangular regions

□ Syntax

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 146/154


with MATLAB, 2nd Edition. CRC Press, 2016
Example 3.67 Compute Again
the Triple Integral
□ Triple integral with cubic region

□ Variable substitution
□ integrand
□ Calculate again, faster

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 147/154


with MATLAB, 2nd Edition. CRC Press, 2016
Example 3.68 Multiple Integral
□ Multiple integral

□ Variables
□ Integrand
□ MATLAB solutions

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 148/154


with MATLAB, 2nd Edition. CRC Press, 2016
Analytical Solution
□ Analytical solution exists

□ Comparison

□ If no analytical solution, numerical solution is


the only choice
5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 149/154
with MATLAB, 2nd Edition. CRC Press, 2016
Example 3.68 Analytical
Solution Does not Exist
□ Numerical solution the only choice

□ Variables
□ integrand
□ MATLAB solutions

5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 150/154


with MATLAB, 2nd Edition. CRC Press, 2016
Summary of the Chapter
□ Calculus invented by Issac Newton and
Gattfried Wilhelm Leibnitz is the foundation of
all science and engineering
□ Symbolic computation in MATLAB is used to
solve limit, derivatives, integrals, sum of series,
Taylor and Fourier series problems
□ Single and multivariable problem
□ Theoretic speaking, all the computation
problems calculus exercise books can be solved
5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 151/154
with MATLAB, 2nd Edition. CRC Press, 2016
View Mathematics from
a New Viewpoint
□ With powerful graphics facilities, find the
quality of finite series approximation, and
select suitable interval.
Avoided by traditional courses
□ Two types of curve integrals, two types of
surface integrals can be solved directly from
formula. Illustrated with examples. How to
turn formula into MATLAB function calls
5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 152/154
with MATLAB, 2nd Edition. CRC Press, 2016
Numerical Differentiation and
Integral Introduced
□ If experimental data rather than math function
is known, how to find derivatives?
Central difference algorithm and implementation
Satisfactory accuracy
□ Various numerical integral algorithms and
functions in MATLAB
When no analytical solution, numerical integral is
the only choice
Treated in the same way
5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing
153/154
with MATLAB, 2nd Edition. CRC Press, 2016
Calculus-related Problems in
Other Chapters
□ Chapter 7, differential equations
□ Chapter 8, numerical differentiation and
integrals with cubic and spline interpolation
□ Chapter 10, Fractional-order calculus
The orders are extended to non-integers
Currently used in many science and engineering
researches
Active and new trend, worth to follow
5/19/2018 Dingyü Xue and YangQuan Chen. Scientific Computing 154/154
with MATLAB, 2nd Edition. CRC Press, 2016

S-ar putea să vă placă și