Lecture 3 Taylor Series Expansion

Slides:



Advertisements
Similar presentations
數值方法 2008, Applied Mathematics NDHU 1 Nonlinear systems Newton’s method The steepest descent method.
Advertisements

Recall Taylor’s Theorem from single variable calculus:
Economics 2301 Lecture 25 Risk Aversion. Figure 7.7 Utility Functions for Risk-Averse and Risk-Loving Individuals.
MATLAB’s extensive, device-independent plotting capabilities are one of its most powerful features. They make it very easy to plot any data at any time.
Part 5 Chapter 19 Numerical Differentiation PowerPoints organized by Dr. Michael R. Gustafson II, Duke University All images copyright © The McGraw-Hill.
High Accuracy Differentiation Formulas
數值方法 2008, Applied Mathematics NDHU 1 Spline interpolation.
Transfer Functions Convenient representation of a linear, dynamic model. A transfer function (TF) relates one input and one output: The following terminology.
What is y=L(x) ? The tangent line is considered as an approximation of the curve y=f(x)
Taylor Series. Theorem Definition The series is called the Taylor series of f about c (centered at c)
Derivatives and Differential Equations
數值方法 2008, Applied Mathematics NDHU1  An iterative approach for root finding  Newton method Lecture 3II Root Finding.
數值方法 2008, Applied Mathematics NDHU 1 Simpson rule Composite Simpson rule.
Chapter 5. Loops are common in most programming languages Plus side: Are very fast (in other languages) & easy to understand Negative side: Require a.
數值方法 2008 Applied Mathematics, NDHU1  Bisection method for root finding  Binary search  fzero Lecture 4.
數值方法 2008 Applied Mathematics, NDHU1  Bisection method for root finding  Binary search  fzero Lecture 4.
Hydroinformatics: Session4 Dr Ivan Stoianov Room 328B Dr Andrew Ireson (Room 304) Mr Juan Rodriguez-Sanchez (411A) Mr Baback.
ES 240: Scientific and Engineering Computation. Chapter 4 Chapter 4: Errors Uchechukwu Ofoegbu Temple University.
數值方法 2008, Applied Mathematics NDHU 1  Nonlinear Recursive relations  Nonlinear recursive relations  Time series prediction  Hill-Valley classification.
數值方法 2008, Applied Mathematics NDHU1  Looping for loop while loop  Break and return  Recursion Lecture 2 Iteration.
Department of Mechanical Engineering, LSU Session IV MATLAB Tutorials Session IV Mathematical Applications using MATLAB Rajeev Madazhy
MA/CS 375 Fall MA/CS 375 Fall 2002 Lecture 31.
An Introduction to MathCAD Finding Solutions and Symbolic Maths.
Numerical Methods for Solving ODEs Euler Method. Ordinary Differential Equations  A differential equation is an equation in which includes derivatives.
數值方法 2008, Applied Mathematics NDHU 1 Numerical Integration.
Finite Difference Methods Definitions. Finite Difference Methods Approximate derivatives ** difference between exact derivative and its approximation.
Numerical Differentiation UC Berkeley Fall 2004, E77 Copyright 2005, Andy Packard. This work is licensed under.
Adavanced Numerical Computation 2008, AM NDHU1 Function approximation Linear models Line fitting Hyper-plane fitting Discriminate analysis Least Square.
Analyzing Functions (4.16) y=f(x) MATLAB. Functional Analysis includes: Plotting and evaluating a function Finding extreme points Finding the roots (zeros.
Numerical Analysis 3D Plots. A numerical method is a technique for computing a numerical approximation of the solution to a mathematical problem.
MA/CS375 Fall MA/CS 375 Fall 2002 Lecture 8.
Recap Cubic Spline Interpolation Multidimensional Interpolation Curve Fitting Linear Regression Polynomial Regression The Polyval Function The Interactive.
數值方法 2008 Applied Mathematics, NDHU1  Lagrange polynomial  Polynomial interpolation Lecture 4II.
數值方法 2008, Applied Mathematics NDHU1 Chaos time series.
1 Lecture 5 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
Basis of Mathematical Modeling LECTURE 3 Numerical Analysis with MATLAB Dr. N.K. Sakhnenko, PhD, Professor Associate.
數值方法 2008, Applied Mathematics NDHU 1 Numerical Differentiation.
TRANSFER FUNCTION Prepared by Mrs. AZDUWIN KHASRI.
1.1 - Functions. Ex. 1 Describe the sets of numbers using set- builder notation. a. {8,9,10,11,…}
The Product Rule. Do Now  Find the derivative of f(x) = x(x 2 + 2x – 1).  What is the derivative of sinx? of cosx?
數值方法, Applied Mathematics NDHU 1 Linear system. 數值方法, Applied Mathematics NDHU 2 Linear system.
Session III Plotting in MATLAB Rajeev Madazhy Dept of Mechanical Engineering LSU MATLAB Tutorials.
數值方法 2008, Applied Mathematics NDHU 1 Ordinary differential equations II Runge-Kutta method.
數值方法 2008, Applied Mathematics NDHU 1 Numerical Integration.
Transfer Functions Convenient representation of a linear, dynamic model. A transfer function (TF) relates one input and one output: The following terminology.
© Dr. Elmer P. Dadios - DLSU Fellow & Professor
The formulae for the roots of a 3rd degree polynomial are given below
Lecture 5 Polynomial Approximation
Applied Numerical Methods
Interpolation Estimation of intermediate values between precise data points. The most common method is: Although there is one and only one nth-order.
Chapter 18.
LECTURE 3 OF SOLUTIONS OF NON -LINEAR EQUATIONS.
Derivative of an Exponential
3.1 – Derivative of a Function
3.1 – Derivative of a Function
A system of nonlinear equations
Taylor series in numerical computations (review)
Numerical Differentiation
Chapter 18.
Use Part 1 of the Fundamental Theorem of Calculus to find the derivative of the function. {image}
SE301: Numerical Methods Topic 8 Ordinary Differential Equations (ODEs) Lecture KFUPM (Term 101) Section 04 Read , 26-2, 27-1 CISE301_Topic8L4&5.
Question Find the derivative of Sol..
Taylor Polynomials & Approximation (9.7)
Expressing functions as infinite series
Function notation.
Define evaluate and compare functions
Linearization of Nonlinear Models
Taylor and Maclaurin Series
Errors and Error Analysis Lecture 2
Presentation transcript:

Lecture 3 Taylor Series Expansion Inline function Taylor series Matlab codes for Taylor series expansion 數值方法2008, Applied Mathematics NDHU

數值方法2008, Applied Mathematics NDHU inline function How to create a function ? Such as f(x)=sin(x)*cos(x) Two steps for creation of an inline function Get a string for representing a valid expression Apply inline.m to translate a string to an inline function 數值方法2008, Applied Mathematics NDHU

數值方法2008, Applied Mathematics NDHU >> g=inline('x^2+1') g = Inline function: g(x) = x^2+1 >> g(2) ans = 5 數值方法2008, Applied Mathematics NDHU

數值方法2008, Applied Mathematics NDHU >> g=inline('x^2+1') g = Inline function: g(x) = x^2+1 >> g(2) ans = 5 數值方法2008, Applied Mathematics NDHU

數值方法2008, Applied Mathematics NDHU Function plot Get a string for representing an expression Apply inline.m to translate a string to an inline function Apply linspace.m to form a linear partition to [-5 5] Determine function outputs of all elements in a partition vector Plot a figure for given function 數值方法2008, Applied Mathematics NDHU

數值方法2008, Applied Mathematics NDHU Input a string, fs f=inline(fs) Use ‘inline’ to generate an inline function x=linspace(-5,5) form a uniform partition to [-5 5] y=f(x) plot(x,y) 數值方法2008, Applied Mathematics NDHU

數值方法2008, Applied Mathematics NDHU Demo Source codes % This example illustrates creation % of an inline function fprintf('input a string to specify a desired fun\n'); fs=input(‘ex. x.^2+2*x+1:','s'); f=inline(fs); range=5; x=-range:0.01:range; y=f(x); plot(x,y); 數值方法2008, Applied Mathematics NDHU

數值方法2008, Applied Mathematics NDHU cos(x) 數值方法2008, Applied Mathematics NDHU

數值方法2008, Applied Mathematics NDHU Input a string, fs f=inline(fs) N=800;d=2; A=rand(2,N); x=A(1,:); y=A(2,:); z=f(x1,x2) plot3(x,y, z, '. ') 數值方法2008, Applied Mathematics NDHU

A sample from function surface f(x,y)=x.^2+3*y.^2 數值方法2008, Applied Mathematics NDHU

數值方法2008, Applied Mathematics NDHU Demo Source codes % Inline function creation % The created inline function has two input arguments % Plot a sample from the function surface fs='x.^2+3*y.^2'; f=inline(fs); a=rand(2,800)*2-1; x=a(1,:);y=a(2,:); z=f(x,y); plot3(x,y,z,'.'); 數值方法2008, Applied Mathematics NDHU

數值方法2008, Applied Mathematics NDHU 3D plot 3d plot t = 0:pi/50:10*pi; plot3(sin(t),cos(t),t); 數值方法2008, Applied Mathematics NDHU

數值方法2008, Applied Mathematics NDHU mesh x=linspace(0,1); x=linspace(-1,1); y=linspace(-1,1)'; X=repmat(x,100,1); Y=repmat(y,1,100); Z=X.^2+Y.^2 mesh(x,y,Z) 數值方法2008, Applied Mathematics NDHU

數值方法2008, Applied Mathematics NDHU surface x=linspace(-1,1); y=linspace(-1,1)'; X=repmat(x,100,1); Y=repmat(y,1,100); surface(x,y,X.^2+Y.^2) shading interp light lighting phong 數值方法2008, Applied Mathematics NDHU

數值方法2008, Applied Mathematics NDHU demo mesh demo_mesh.m Key in a 2D function:cos(x+y) 數值方法2008, Applied Mathematics NDHU

數值方法2008, Applied Mathematics NDHU Taylor series 數值方法2008, Applied Mathematics NDHU

數值方法2008, Applied Mathematics NDHU Taylor’s Theorem 數值方法2008, Applied Mathematics NDHU

數值方法2008, Applied Mathematics NDHU Taylor’s Theorem Approximate f(x) by first n+1 terms of Taylor series Truncating error: 數值方法2008, Applied Mathematics NDHU

Taylor series expansion 數值方法2008, Applied Mathematics NDHU

數值方法2008, Applied Mathematics NDHU c=1,n=3 數值方法2008, Applied Mathematics NDHU

數值方法2008, Applied Mathematics NDHU Normal function function y=f_normal(x) y=1/sqrt(2*pi)*exp(-x.^2); return source code x=linspace(-5,5); >> plot(x,f_normal(x)) 數值方法2008, Applied Mathematics NDHU

Taylor expansion at c=1 with n=0 數值方法2008, Applied Mathematics NDHU

Taylor expansion at c=1 with n=1 數值方法2008, Applied Mathematics NDHU

Taylor expansion at c=1 with n=2 數值方法2008, Applied Mathematics NDHU

數值方法2008, Applied Mathematics NDHU Taylor expansion at c=1 with n=3 數值方法2008, Applied Mathematics NDHU

數值方法2008, Applied Mathematics NDHU Taylor expansion Source code Taylor_nor % Taylor expansion % f(x)=1/sqrt(2pi)*exp(-x^2); x=linspace(0.6,1.4,500); n=length(x); c=1; for i=1:n y1(i)=f_nm(c); y2(i)=-2*c*f_nm(c)*(x(i)-c); y3(i)=(4*c^2-2)*f_nm(c)/2*(x(i)-c)^2; y4(i)=(12*c-8*c^3)*f_nm(c)/6*(x(i)-c)^3; end plot(x,f_nm(x));hold on;plot(x,y1,'r'); title('one term'); figure; plot(x,f_nm(x));hold on;plot(x,y1+y2,'r');title('two terms'); figure; plot(x,f_nm(x));hold on;plot(x,y1+y2+y3,'r');title('three terms'); figure; plot(x,f_nm(x));hold on;plot(x,y1+y2+y3+y4,'r');title('four terms'); 數值方法2008, Applied Mathematics NDHU

Symbolic differentiation Use diff.m to find the derivative of a function diff Input: a string for representing a valid expression Output: the derivative of a given expression 數值方法2008, Applied Mathematics NDHU

數值方法2008, Applied Mathematics NDHU >> x=sym('x'); >> diff(x.^2) ans = 2*x 數值方法2008, Applied Mathematics NDHU

數值方法2008, Applied Mathematics NDHU Derivative Form a string >> ss='x.^2'; >> inst=['diff(' ss ')']; >> eval(inst) ans = 2*x Form an instruction Evaluate the Instruction by calling eval 數值方法2008, Applied Mathematics NDHU

數值方法2008, Applied Mathematics NDHU eval Execute a string that collects MATLAB instructions Ex: >> ss='x=linspace(-2*pi,2*pi);plot(x,cos(x))'; >> eval(ss) 數值方法2008, Applied Mathematics NDHU

數值方法2008, Applied Mathematics NDHU diff source codes f_diff % input a string to specify a function % find its derivative ss=input('function:','s'); fx=inline(ss); ss=['diff(' ss ')']; ss1=eval(ss); fx1=inline(ss1) 數值方法2008, Applied Mathematics NDHU

數值方法2008, Applied Mathematics NDHU Example >> f_diff function:cos(x) 數值方法2008, Applied Mathematics NDHU

數值方法2008, Applied Mathematics NDHU Derivative % input a string to specify a function % plot its derivative ss=input('function of x:','s'); fx=inline(ss); x=sym('x'); ss=['diff(' ss ')']; ss1=eval(ss); fx1=inline(ss1) x=linspace(-1,1); plot(x,fx(x),'b');hold on; plot(x,fx1(x),'r'); source code : f_diff2 數值方法2008, Applied Mathematics NDHU

數值方法2008, Applied Mathematics NDHU 2nd derivative source codes f_diff3.m 數值方法2008, Applied Mathematics NDHU

數值方法2008, Applied Mathematics NDHU Example >> f_diff3 function of x:x.^3-2*x+1 fx1 = Inline function: fx1(x) = 3.*x.^2-2 fx2 = fx2(x) = 6.*x 數值方法2008, Applied Mathematics NDHU

數值方法2008, Applied Mathematics NDHU Example >> f_diff3 function of x:tanh(x) fx1 = Inline function: fx1(x) = 1-tanh(x).^2 fx2 = fx2(x) = -2.*tanh(x).*(1-tanh(x).^2) 數值方法2008, Applied Mathematics NDHU

數值方法2008, Applied Mathematics NDHU Exercise ex3.pdf 數值方法2008, Applied Mathematics NDHU