Numerical Differentiation Methods

Slides:



Advertisements
Similar presentations
Chapter 6 Differential Equations
Advertisements

Computational Methods in Physics PHYS 3437
Numerical Computation
Lecture 18 - Numerical Differentiation
CE33500 – Computational Methods in Civil Engineering Differentiation Provided by : Shahab Afshari
Lecture 2: Numerical Differentiation. Derivative as a gradient
458 Interlude (Optimization and other Numerical Methods) Fish 458, Lecture 8.
Chapter 1 Introduction The solutions of engineering problems can be obtained using analytical methods or numerical methods. Analytical differentiation.
I.1 ii.2 iii.3 iv.4 1+1=. i.1 ii.2 iii.3 iv.4 1+1=
Second Term 05/061 Part 3 Truncation Errors (Supplement)
ECIV 301 Programming & Graphics Numerical Methods for Engineers Lecture 5 Approximations, Errors and The Taylor Series.
I.1 ii.2 iii.3 iv.4 1+1=. i.1 ii.2 iii.3 iv.4 1+1=
Dr. Jie Zou PHY Chapter 7 Numerical Differentiation: 1 Lecture (I) 1 Ref: “Applied Numerical Methods with MATLAB for Engineers and Scientists”, Steven.
The Islamic University of Gaza Faculty of Engineering Civil Engineering Department Numerical Analysis ECIV 3306 Chapter 23 Numerical Differentiation.
Numerical Differentiation:1* Lecture (II)
ECIV 301 Programming & Graphics Numerical Methods for Engineers Lecture 27 Numerical Integration & Differentiation.
Numerical Differentiation
Numerical Integration Methods
Today’s class Numerical Integration Newton-Cotes Numerical Methods
Interpolation. Interpolation is important concept in numerical analysis. Quite often functions may not be available explicitly but only the values of.
EE3561_Unit 8Al-Dhaifallah14351 EE 3561 : Computational Methods Unit 8 Solution of Ordinary Differential Equations Lesson 3: Midpoint and Heun’s Predictor.
1 EEE 431 Computational Methods in Electrodynamics Lecture 4 By Dr. Rasime Uyguroglu
+ Numerical Integration Techniques A Brief Introduction By Kai Zhao January, 2011.
Boundary Value Problems l Up to this point we have solved differential equations that have all of their initial conditions specified. l There is another.
Finite Difference Methods Definitions. Finite Difference Methods Approximate derivatives ** difference between exact derivative and its approximation.
Today’s class Numerical Differentiation Finite Difference Methods Numerical Methods Lecture 14 Prof. Jinbo Bi CSE, UConn 1.
Sensitivity derivatives Can obtain sensitivity derivatives of structural response at several levels Finite difference sensitivity (section 7.1) Analytical.
559 Fish 559; Lecture 5 Non-linear Minimization. 559 Introduction Non-linear minimization (or optimization) is the numerical technique that is used by.
Dr. Jie Zou PHY Chapter 2 Solution of Nonlinear Equations: Lecture (II)
Today’s class Ordinary Differential Equations Runge-Kutta Methods
Ordinary Differential Equations
NUMERICAL DIFFERENTIATION or DIFFERENCE APPROXIMATION Used to evaluate derivatives of a function using the functional values at grid points. They are.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Chapter 21 Numerical Differentiation.
Numerical Integration Methods
Numerical Methods Some example applications in C++
Differentiation and integration in R
Section 14.2 Computing Partial Derivatives Algebraically
Root Finding Methods Fish 559; Lecture 15 a.
Chapter 10 Limits and the Derivative
Numerical Differentiation
Non-linear Minimization
Derivative of an Exponential
Numerical Differentiation
Interpolation Methods
PSG College of Technology
Taylor series in numerical computations (review)
Numerical Analysis Lecture 27.
Numerical Differentiation
Interpolation.
Roundoff and Truncation Errors
SE301: Numerical Methods Topic 8 Ordinary Differential Equations (ODEs) Lecture KFUPM (Term 101) Section 04 Read , 26-2, 27-1 CISE301_Topic8L4&5.
CSE Differentiation Roger Crawfis.
Chapter 23.
Ordinary differential equaltions:
Numerical Differentiation Chapter 23
Numerical Integration:
Interpolation Methods
Numerical Differentiation Methods
SE301: Numerical Methods Topic 8 Ordinary Differential Equations (ODEs) Lecture KFUPM (Term 101) Section 04 Read , 26-2, 27-1 CISE301_Topic8L2.
Numerical Analysis Lecture 2.
Numerical Integration Methods
6 Numerical Differentiation
-4 is the y-value or the function value.
Chapter 1 / Error in Numerical Method
Roundoff and Truncation Errors
Chapter 2 Limits and the Derivative
1 Newton’s Method.
Lagrange Remainder.
Derivatives and Gradients
Presentation transcript:

Numerical Differentiation Methods Fish 559; Lecture 11 a

Symbolic vs Numerical Differentiation Differentiation is algorithmic - there is no function that cannot be differentiated (given patience and a large piece of paper). Many packages (including R) include symbolic differentiation routines. These apply an algorithm to provide code which computes the derivatives analytically. Numerical differentiation involves applying approximations to calculate the value of the derivative at a given point.

Symbolic differentiation in R-I The function “D”, called as follows, does symbolic differentiation: This is NOT a a very smart function: my.deriv <- function(mathfunc, var) { temp <- substitute(mathfunc) name <- deparse(substitute(var)) D(temp, name) } > my.deriv(x*x^2,x) x^2 + x * (2 * x)

Symbolic differentiation in R-II D can, however, be quite useful: However, D may crash for complicated formulae. > my.deriv(x*(1-x)-a*x*v/(x+d),x) (1 - x) - x - (a * v/(x + d) - a * x * v/(x + d)^2) > my.deriv(x*(1-x)-a*x*v/(x+d),v) - (a * x/(x + d))

The Deriv function-I Numerical methods often require the derivatives of functions. R includes the function “deriv” which calculates gradients: ff <- deriv(expression, name, function name) For example: This creates a function ff. ff<-deriv(~x*(1-x)-a*x*v/(x+d),c("x","v"), function(x,v,a,d) NULL, formal=T)

The Deriv function-II function(x, v, a, d) { .expr1 <- 1 - x .expr3 <- a * x .expr4 <- .expr3 * v .expr5 <- x + d .value <- (x * .expr1) - (.expr4/.expr5) .grad <- array(0, c(length(.value), 2), list(NULL, c("x", "v"))) .grad[, "x"] <- (.expr1 - x) - (((a * v)/.expr5) - (.expr4/(.expr5^2))) .grad[, "v"] <- - (.expr3/.expr5) attr(.value, "gradient") <- .grad .value }

Calculating Derivatives Numerically-I Sometimes calculating derivatives analytically can get rather tedious. For example, for the dynamic Schaefer model: I think you get the picture…

Calculating Derivatives Numerically-II Methods of numerical differentiation rely on Taylor series’ approximations to functions, i.e.:

Calculating Derivatives Numerically-III Two common approximations to exist. Both rely on two function evaluations – which is to be preferred? We can compare them in terms of how well they mimic the Taylor series expansion of f

Calculating Derivatives Numerically-IV Therefore: Applying the same approach to leads to: The “central difference” approach is therefore clearly preferable if “h is small”.

Does the Previous Result Hold up in Reality-I? Derivative at x=0.5 (h=0.0001) True: 1.001067 Central difference: 1.001067 Right difference: 1.001198

Does the Previous Result Hold up in Reality-II? Derivative at x=0.5 (h=h <- 0.0000000000000001) True: 1.001067 Central difference: 2.220446 Right difference: 4.440892 So what happened?

Calculating Derivatives Numerically-V When I need an accurate approximation to a derivative, I have tended to use the four-point “central difference” approximation. Central differences perform badly when calculating derivatives on a boundary.

Calculating Derivatives Numerically The accuracy of the approximation depends on the number of terms and the size of h / k (smaller – but not too small – is better)