MATLAB ExamplesNumerical DifferentiationHans-Petter Halvorsen
Numerical DifferentiationThe derivative of a function π¦ π(π₯)is a measure of how π¦ changes withπ₯.A numerical approach to the derivative of a function π¦ π(π₯) is:Note! We will use MATLAB in order to find the numeric solution β not the analytic solution
Numerical DifferentiationMATLAB Functions for Numerical Differentiation:diff()polyder()MATLAB is a numerical language and do not perform symbolicmathematics. well, that is not entirely true because there is βSymbolicToolboxβ available for MATLAB.
Numerical DifferentiationGiven the following equation:π¦ π₯ ' 2π₯ * π₯ 3 Find-.-/analytically (use βpen and paperβ). Define a vector x from -5 to 5 and use the diff() function to .approximate the derivative y with respect to x ( ). / Compare the data in a 2D array and/or plot both the exact value-.of and the approximation in the same plot.-/ Increase number of data point to see if there are any difference.
Given the following equation:π¦ π₯ ' 2π₯ * π₯ 3Then we can get the analytically solution:ππ¦ 3π₯ * 4π₯ 1ππ₯
Symbolic Math ToolboxWe start by finding the derivate of f(x) using the Symbolic Math Toolbox:clearclcsyms f(x)syms xf(x) x 3 2*x 2 -x 3This gives:dfdt(x) 3*x 2 4*x - 1dfdt diff(f, x, arted-with-symbolic-math-toolbox.html
x -5:1:5;% Define the function y(x)y x. 3 2*x. 2 - x 3;% Plot the function y(x)plot(x,y)title('y')% Find nummerical solution to dy/dxdydx num diff(y)./diff(x);dydx exact 3*x. 2 4.*x -1;dydx [[dydx num, NaN]', dydx exact']% Plot nummerical vs analytical solution to dy/dxfigure(2)plot(x,[dydx num, NaN], x, dydx exact)title('dy/dx')legend('numerical solution', 'analytical solution')Numerical SolutionExact Solution
π¦ π₯ ' 2π₯ * π₯ 3ππ¦ 3π₯ * 4π₯ 1ππ₯x -5:1:5;
ππ¦ 3π₯ * 4π₯ 1ππ₯x -5:0.1:5;x -5:0.01:5;
Differentiation on PolynomialsGiven the following equation:π¦ π₯ ' 2π₯ * π₯ 3Which is also a polynomial. A polynomial can be written on thefollowing general form: π¦ π₯ π5 π₯ 6 π7 π₯ 687 π687 π₯ π6 We will use Differentiation on the Polynomial to find-.-/From previous we know that the Analytically solution is:ππ¦ 3π₯ * 4π₯ 1ππ₯
p [1 2 -1 3];π¦ π₯ ' 2π₯ * π₯ 3polyder(p)ans 34-1ππ¦ 3π₯ * 4π₯ 1ππ₯We see we get the correct answer
Differentiation on PolynomialsFind the derivative for the product:3π₯ * 6π₯ 9 π₯ * 2π₯We will use the polyder(a,b) function.Another approach is to use define is to first use the conv(a,b)function to find the total polynomial, and then use polyder(p)function.Try both methods, to see if you get the same answer.
% Define the polynomialsp1 [3 6 9];p2 [1 2 0]; %Note!% Method 1polyder(p1,p2)ans 124218p 3% Method 2p conv(p1,p2)polyder(p)36ans 1212362142As expected, the result are the same for the 2 methods used above.For more details, see next page.18180
We have thatandπ1 3π₯ 2 6π₯ 9π2 π₯ 2 2π₯The total polynomial becomes then:π π1 π2 3π₯ 4 12π₯ 3 21π₯ 2 18π₯As expected, the results are the same for the 2 methods used above:ππ π(3π₯ 4 12π₯ 3 21π₯ 2 18π₯) 12π₯ 3 36π₯ 2 42π₯ 18ππ₯ππ₯
Hans-Petter Halvorsen, M.Sc.University College of Southeast Norwaywww.usn.noE-mail: hans.p.halvorsen@hit.noBlog: http://home.hit.no/ hansha/
Numerical Differentiation A numerical approach to the derivative of a function ! #(%)is: Note! We will use MATLAB in order to find the numericsolution βnot the analytic solution The derivative
MATLAB tutorial . School of Engineering . Brown University . To prepare for HW1, do sections 1-11.6 β you can do the rest later as needed . 1. What is MATLAB 2. Starting MATLAB 3. Basic MATLAB windows 4. Using the MATLAB command window 5. MATLAB help 6. MATLAB βLive Scriptsβ (for algebra, plotting, calculus, and solving differential .
19 MATLAB Excel Add-in Hadoop MATLAB Compiler Standalone Application MATLAB deployment targets MATLAB Compiler enables sharing MATLAB programs without integration programming MATLAB Compiler SDK provides implementation and platform flexibility for software developers MATLAB Production Server provides the most efficient development path for secure and scalable web and enterprise applications
MATLAB tutorial . School of Engineering . Brown University . To prepare for HW1, do sections 1-11.6 β you can do the rest later as needed . 1. What is MATLAB 2. Starting MATLAB 3. Basic MATLAB windows 4. Using the MATLAB command window 5. MATLAB help 6. MATLAB βLive Scriptsβ (for
3. MATLAB script files 4. MATLAB arrays 5. MATLAB twoβdimensional and threeβdimensional plots 6. MATLAB usedβdefined functions I 7. MATLAB relational operators, conditional statements, and selection structures I 8. MATLAB relational operators, conditional statements, and selection structures II 9. MATLAB loops 10. Summary
Automatic Differentiation Introductions Automatic Differentiation What is Automatic Differentiation? Algorithmic, or automatic, differentiation (AD) is concerned with the accurate and efο¬cient evaluation of derivatives for functions deο¬ned by computer programs. No truncation errors are incurred, and the resulting numerical derivative
foundation of basic MATLAB applications in engineering problem solving, the book provides opportunities to explore advanced topics in application of MATLAB as a tool. An introduction to MATLAB basics is presented in Chapter 1. Chapter 1 also presents MATLAB commands. MATLAB is considered as the software of choice. MATLAB can be used .
I. Introduction to Programming Using MATLAB Chapter 1: Introduction to MATLAB 1.1 Getting into MATLAB 1.2 The MATLAB Desktop Environment 1.3 Variables and Assignment Statements 1.4 Expressions 1.5 Characters and Encoding 1.6 Vectors and Matrices Chapter 2: Introduction to MATLAB Programming 2.1 Algorithms 2.2 MATLAB Scripts 2.3 Input and Output
Topographical Anatomy A working knowledge of human anatomy is important for you as an EMT. By using the proper medical terms, you will be able to communicate correct information to medical professionals with the least possible confusion. At the same time, you need to be able to communicate with others who may or may not understand medical terms. Balancing these two facets is one of the most .