Welcome to my computer life.The blog is in building, please waiting for a transformation of it.
Numberical Analysis --- Numerical Differentiation and Integration
获取链接
Facebook
X
Pinterest
电子邮件
其他应用
-
Welcome file
Numerical Differentiation
Given x0, approximate f′(x0). f′(x0)=h→0limhf(x0+h)−f(x0) ⇒f′(x0)≈hf(x0+h)−f(x0)(forward) ⇒f′(x0)≈hf(x0)−f(x0−h)(backward)
Approximate f(x) by its Lagrange polynomial with interpolating points x0 and x0+h: f(x)=x0−x0−hf(x0)(x−x0−h)+x0+h−x0f(x0+h)(x−x0)+2(x−x0)(x−x0−h)f′′(ξx)
Approximate f(x) by its Lagrange polynomial with interpolating points {x0,x1,...,xn}. f(x)=k=0∑nf(xk)Lk(x)+(n+1)!(x−x0)...(x−xn)f(n+1)(ξx) f′(xj)=k=0∑nf(xk)Lk′(xj)+(n+1)!f(n+1)(ξj)0≤k≤n,k=j∏(xj−xk)
Note:
In general, more evaluation points produce greater accuracy.
On the other hand, the number of functional evaluations grows and the roudoff error increases. Hence the numerical differentiation is unstable!
Example: Given three points x0,x0+h and x0+2h, please derive the three-point formulae for each of the points. Then give the best three-point formulae for f′(x). f′(x0)=h1[−23f(x0)+2f(x0+h)−21f(x0+2h)]+3h2f(3)(ξ0) f′(x0+h)=h1[−21f(x0)+21f(x0+2h)]−6h2f(3)(ξ1) f′(x0)=2h1[f(x0+h)−f(x0−h)]−6h2f(3)(ξ1)
Example: Find a way to approximate f′′(x0).
Consider Taylor expansion of f(x0+h) and f(x0−h) at x0: f(x0+h)=f(x0)+f′(x0)h+21f′′(x0)h2+61f′′′(x0)h3+241f(4)(ξ1)h4 f(x0−h)=f(x0)−f′(x0)h+21f′′(x0)h2−61f′′′(x0)h3+241f(4)(ξ−1)h4
Integrate the Lagrange interpolating polynomial of f(x) instead.
Select a set of distinct nodes a≤x0<x1<...<xn≤b from [a,b]. The Lagrange polynomial is Pn(x)=k=0∑nf(xk)Lk(x) ∫abf(x)dx≈k=0∑nf(xk)∫abLk(x)dx Ak=∫abLk(x)dx=∫abj=k∏(xk−xj)(x−xj)dx ErrorR[f]=∫abf(x)dx−k=0∑nAkf(xk)=∫ab[f(x)−Pn(x)]dx=∫abRn(x)dx=∫ab(n+1)!f(n+1)(ξx)k=0∏n(x−xk)dx
Definition: The degree of accuracy, or precision, of a quadrature formulae is the largest positive integer n such that the formulae is exact for xk for each k=0,1,...,n.
Example: Consider the linear interpolation on [a,b], we have P1(x)=a−bx−bf(a)+b−ax−af(b) ⇒A1=A2=2b−a⇒∫abf(x)dx≈2b−a[f(a)+f(b)]
Solution: Consider xk for each k=0,1,... x0=1:∫ab1dx=b−a=2b−a[1+1] x:∫abxdx=2b2−a2=2b−a[a+b] x2:∫abx2dx=3b3−a3=2b−a[a2+b2]
For equally spaced nodes: xi=a+ih,h=nb−a,i=0,1,...,n Ai=∫x0xnj=i∏(xi−xj)(x−xj)dx=∫0ni=j∏(i−j)h(t−j)h×hdt=ni!(n−i)!(b−a)(−1)n−1∫0ni=j∏(t−j)dt
Note: Cotes coefficients does not depend on either f(x) or [a,b], and can be determined by n and i only. Hence we can find these coefficients from a table. The formulae are called Newton-Cotes formulae.
Theorem: For the (n+1)-point closed Newton-Cotes formulae, there exists ξ∈(a,b) for which ∫abf(x)dx=k=0∑nAkf(xk)+(n+2)!hn+3f(n+2)(ξ)∫0nt2(t−1)...(t−n)dt
if n is even and f∈Cn+2[a,b], and ∫abf(x)dx=k=0∑nAkf(xk)+(n+1)!hn+2f(n+1)(ξ)∫0nt(t−1)...(t−n)dt
if n is odd and f∈Cn+1[a,b]
Composite Numerical Integration
Due to the osillatory nature of high-degree polynomials, piecewise interpolation is applied to approximate f(x)⇒ a piecewise approach that uses the low-order Newton-Cotes formulae.
Apply Trapezoidal Rule on each [xk−1,xk]: ∫xk−1xkf(x)dx≈2xk−xk−1[f(xk−1)+f(xk)],k=1,...,n ∫abf(x)dx≈k=1∑n2h[f(xk−1)+f(xk)]=2h[f(a)+2k=1∑n−1f(xk)+f(b)]=Tn R[f]=k=1∑n[−12h3f′′(ξx)]=−12h2(b−a)nk=1∑nf′′(ξx)=−12h2(b−a)f′′(ξ),ξ∈(a,b)
Note: To simplify the notation, we may let n′=2n. Then h′=n′b−a=2h,xk=a+kh′ and Sn=3h′[f(a)+4odd k∑f(xk)+2even k∑f(xk)+f(b)]
Composite integration techniques are all stable.
Example: Consider the Simpson’s Rule with n subintervals on [a,b]. Assume that f(xi) is approximated by f∗(xi) such that f(xi)=f∗(xi)+ϵi for each i=0,1,...,n. Then the accumulated error e(h) is e(h)=∣∣3h[ϵ0+4odd k∑ϵk+2even k∑ϵk+ϵn]∣∣
If ∣ϵi∣<ϵ for all i=0,1,...,n, then e(h)<3h[ϵ+4(n/2)ϵ+2(n/2−1)ϵ+ϵ]=nhϵ=(b−a)ϵ
When we refine the partition to ensure accuracy, the increased computation will NOT increase the roundoff error.
Example: Use Trapezoidal rule and Simpson’s rule with n=8 to approximate π=∫011+x24dx.
Solution: Set xk=8k T8=161[f(0)+2k=1∑7f(xk)+f(1)]=3.138988494 S4=241[f(0)+4odd∑f(xk)+2even∑f(xk)+f(1)]=3.141592502
When programming we usually keep dividing the subintervals into 2 equally spaced smaller subintervals. That is, take n=2k for k=0,1,.... When k=9,T512=3.14159202 34T8−31T4=3.141592502=S4
Romberg Integration
Since the error of Trapezoidal rule is Rn[f]=−12h2(b−a)f′′(ξ), when we reduce the length of each subinterval into a half, R2n[f]=−(2h)2121f′′(ξ′)≈41Rn[f] ⇒I−TnI−T2n≈41
Solve for I: I≈4−14T2n−Tn=34T2n−31Tn=Sn
In general: 4−14T2n−Tn=Sn42−142S2n−Sn=Cn43−143C2n−Cn=Rn
Richardson’s Extrapolation
Generate high-accuracy results while using lower-order formulae. Suppose that for some h=0, we have a formula T0(x) that approximates an unknown I, and that the truncation error has the form: T0(h)−I=α1h+α2h2+...
Replace h by half its value, we have T0(2h)−I=α1(h/2)+α2(h/2)2+...
How to improve the accuracy from O(h) to O(h2)? 2−12T0(2h)−T0(h)−I=−21α2h2−43α3h3−...
Predict the amount of functional variation and adapt the step size to the varying requirements.
Example: Consider the adaptive method based on Composite Simpson’s rule. ∫abf(x)dx=S(a,b)−90h5f(4)(ξ)
where S(a,b)=3h[f(a)+4f(a+h)+f(b)],h=2b−a
Let S(a,2a+b)=6h[f(a)+4f(a+2h)+f(a+h)] S(2a+b,b)=6h[f(a+h)+4f(a+23h)+f(b)]
Then ∫abf(x)dx=S(a,2a+b)+S(2a+b,b)−161×90h5f(4)(η) ∣∣∫abf(x)dx−S(a,2a+b)−S(2a+b,b)∣∣≈151∣∣S(a,b)−S(a,2a+b)−S(2a+b,b)∣∣<ϵ
Gaussian Quadrature
Construct a formula ∫abw(x)f(x)dx≈k=0∑nAkf(xk) of precision degree 2n+1 with n+1 points.
Determine 2n+2 unknowns x0,...,xn and A0,..,An such that the formula is accurate for f(x)=1,x,x2,...,x2n+1. The points x0,...,xn are called Gaussian points, and the method is called Gaussian quadrature.
Example: Approximate ∫01xf(x)dx using Gaussian quadrature with n=1.
Solution: Assume ∫01xf(x)dx=A0f(x0)+A1f(x1)
The formula must be accurate for f(x)=1,x,x2,x3 ⎩⎨⎧32=A0+A152=A0x0+A1x172=A0x02+A1x1292=A0x03+A1x13⇒⎩⎨⎧x0≈0.8212x1≈0.2899A0≈0.3891A1≈0.2776
Theorem:x0,...,xn are Gaussian points iff W(x)=k=0∏n(x−xk) is orthogonal to all the polynomials of degree no greater than n.
Proof:
If x0,...,xn are Gaussian points, then the degree of precision of the formula ∫abw(x)f(x)dx≈k=0∑nAkf(xk) is at least 2n+1. Then for any polynomial Pm(x) with m≤n, the degree of Pm(x)W(x) must be no greater than 2n+1. Hence the formula is accurate for Pm(x)W(x). That is ∫abw(x)Pm(x)W(x)dx=k=0∑nAkPm(xk)W(xk)=0
To prove that x0,...,xn are Gaussian points, we just have to prove that the formula is accurate for any polynomial Pm(x) with m≤2n+1. Let Pm(x)=W(x)q(x)+r(x). Then ∫abw(x)Pm(x)dx=∫abw(x)W(x)q(x)dx+∫abw(x)r(x)dx=k=0∑nAkr(xk)=k=0∑nAkPm(xk)
The set of orthogonal polynomials {φ0,φ1,...,φn,...} is linearly independent and φn+1 is orthogonal to any polynomial Pm(x) with m≤n.⇒ If we take φn+1 to be W(x), then the roots of φn+1 are the Gaussian points.
Example: Approximate ∫01xf(x)dx using Gaussian quadrature with n=1.
Step 1:
Construct the orthogonal polynomial φ2. Let φ0(x)=1,φ1(x)=x+a,φ2(x)=x2+bx+c (φ0,φ1)=0⇒∫01x(x+a)dx=0⇒a=−53 (φ0,φ2)=0⇒∫01x(x2+bx+c)dx=0 (φ1,φ2)=0⇒∫01x(x−53)(x2+bx+c)dx=0 ⇒{b=−910c=215⇒φ2(x)=x2−910x+215
Step 2:
Find the two roots of φ2 which are the Gaussian points x0 and x1: x0;1=210/9±(10/9)2−20/21
Step 3:
Since the formula must be accurate for f(x)=1,x, we can easily solve a linear system of equations for A0 and A1. The results are the same as we have obtained: x0≈0.8212,x1≈0.2899,A0≈0.3891,A1≈0.2776
Use this formula to approximate ∫01xexdx≈1.2555
Some special families of orthogonal functions
1.Legendre Polynomials: Defined on [−1,1] with w(x)≡1. Pk(x)=2kk!1dxkdk(x2−1)k(Pk,Pl)={0k=l2k+12k=l
From P0=1 and P1=x we have (k+1)Pk+1=(2k+1)xPk−kPk−1
The formula that uses the roots of Pn+1 is called the Gauss-Legendre quadrature formula.
2.Chebyshev Polynomials:
Defined on [−1,1] with w(x)=1−x21
The roots of Tn+1 are xk=cos(2n+22k+1π) for k=0,...,n.
The formula ∫−111−x21f(x)dx=k=0∑nAkf(xk)
is called the Gauss-Chebyshev quadrature formula.
Welcome file If a function y = f ( x ) y=f(x) y = f ( x ) is too complicated for calculation or is even unknown, one way to approximate it is to first obtain its values y 0 = f ( x 0 ) , . . . , x n = f ( x n ) y_0=f(x_0),...,x_n=f(x_n) y 0 = f ( x 0 ) , ... , x n = f ( x n ) at a sequence of points x 0 , . . . , x n x_0,...,x_n x 0 , ... , x n , and then construct a relatively simple approximating function g ( x ) ≈ f ( x ) g(x)\approx f(x) g ( x ) ≈ f ( x ) . If g ( x ) g(x) g ( x ) satisfies that g ( x i ) = f ( x i ) g(x_i)=f(x_i) g ( x i ) = f ( x i ) for all i = 0 , . . . , n i=0,...,n i = 0 , ... , n , it is called the interpolating function of f ( x ) f(x) f ( x ) . The most commonly used interpolating functions are algebraic polynomials. Interpolation and the Lagrange Polynomial Find a polynomial of degree n n n , P n ( x ) = a 0 + a 1 x + . . . + a n x n P_n(x)=a_0+a_1x+...+a_nx^n P n ( x ) = a 0 + a 1 x + ... + a n x...
Welcome file Lecture 4: Keyframe interpolation and velocity control 动画中的运动感控制 : 运动的表示: 用数学方法来表示各类物体的运动 运动的控制和编辑: 给动画师提供能够表达他意图的方便、直观的控制工具 运动的生成: 计算每一帧所需的各种运动参数 Goal:再现物理世界的运动,超越物理世界的运行。 I.Interpolation between key frames 1. Parameters to be interpolated : Position of an object Scale of an object Orientation of an object Joint angle between two joints Color attribute of an object 2. Interpolation between frames is not trivial : Appropriate interpolation function Parameterization of the function Maintain the desired control of the interpolated values over time 3. Solution : Generate a space curve Distribute points evenly along curve Speed control: vary points 4. Interpolation v.s. Approximation : An interpolating spline in which the spline passes through the interior control points. An approximating spline in which only the endpoints are interpolated; the interior control points are used only to design th...
Welcome file Lecture 3: Representation of transformation and rotation Motion Specification : Low level techniques (techniques that aid the animator in precisely specifying motion) High level techniques (techniques used to describe general motion behavior) Translate, scale and rotation are all below to low level. Transformation can be used to change the position of objects; Set animations for objects and light source. Technical Background : Spaces and transformations: Coordinate Space: left-handed, right-handed, local coordinates system, global coordinates system. Viewing pipeline: Homogeneous coordinate, Transformation matrix, Matrix Concatenation Orientation representation: Rotation matrix Fixed angle Euler angle Angle and Axis Quaternion I.Representation of Transformation 1.1.3-D Transformations Translate, scale, or rotate a point p p p to p ′ p' p ′ : p ′ = p + T p'=p+T p ′ = p + T p ′ = S p p'=Sp ...