Introduction to Programming for Mechanical Engineers (ME 319)

Slides:



Advertisements
Similar presentations
Numerical Integration
Advertisements

CSE 123 Symbolic Processing. Declaring Symbolic Variables and Constants To enable symbolic processing, the variables and constants involved must first.
Numerical Differentiation and Quadrature (Integration) 1Daniel Baur / Numerical Methods for Chemical Engineers / Numerical Quadrature Daniel Baur ETH Zurich,
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Introduction to MATLAB 7 for Engineers William J. Palm.
Lecture 16 Symbolic Mathematics Symbolic mathematics: algebraezplotcalculus © 2007 Daniel Valentine. All rights reserved. Published by Elsevier.
Numerical Integration of Functions
By Hrishikesh Gadre Session II Department of Mechanical Engineering Louisiana State University Engineering Equation Solver Tutorials.
MANE 4240 & CIVL 4240 Introduction to Finite Elements Numerical Integration in 1D Prof. Suvranu De.
Matlab Matlab is a powerful mathematical tool and this tutorial is intended to be an introduction to some of the functions that you might find useful.
CHAPTER 4 THE DEFINITE INTEGRAL.
Numerical Integration
Introduction to MATLAB for Engineers, Third Edition William J. Palm III Chapter 7 Statistics, Probability, and Interpolation PowerPoint to accompany Copyright.
CISE301_Topic7KFUPM1 SE301: Numerical Methods Topic 7 Numerical Integration Lecture KFUPM Read Chapter 21, Section 1 Read Chapter 22, Sections 2-3.
CISE301_Topic71 SE301: Numerical Methods Topic 7 Numerical Integration Lecture KFUPM (Term 101) Section 04 Read Chapter 21, Section 1 Read Chapter.
Numerical Integration UC Berkeley Fall 2004, E77 Copyright 2005, Andy Packard. This work is licensed under the.
Numerical Computation
ACSL, POSTECH1 MATLAB 입문 CHAPTER 8 Numerical calculus and differential equations.
Chapter 9 Introduction to MATLAB for Engineers, Third Edition
CMPS1371 Introduction to Computing for Engineers NUMERICAL METHODS.
Chapters 5 and 6: Numerical Integration
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Introduction to MATLAB 7 for Engineers William J. Palm.
Chapter 9 Numerical Integration Flow Charts, Loop Structures Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Chapter 12 Review: Symbolic Mathematics
ME 2304: 3D Geometry & Vector Calculus Dr. Faraz Junejo Gradient of a Scalar field & Directional Derivative.
5.c – The Fundamental Theorem of Calculus and Definite Integrals.
EE3561_Unit 7Al-Dhaifallah EE 3561 : Computational Methods Unit 7 Numerical Integration Dr. Mujahed AlDhaifallah ( Term 342)
Introduction To this point MATLAB has been used to answer questions with a numeric value ▫Variables are assigned specific values ▫Answers are numbers MATLAB.
Math b (Discrete) Random Variables, Binomial Distribution.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. A Concise Introduction to MATLAB ® William J. Palm III.
Numerical Differentiation and Quadrature (Integration)
1 Lecture 1 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
Numerical Analysis 3D Plots. A numerical method is a technique for computing a numerical approximation of the solution to a mathematical problem.
ACSL, POSTECH1 MATLAB 입문 CHAPTER 8 Numerical calculus and differential equations.
Recap Cubic Spline Interpolation Multidimensional Interpolation Curve Fitting Linear Regression Polynomial Regression The Polyval Function The Interactive.
More Functions in MATLAB. Functions that operate on other functions A function F() can take another function G() as an argument by using a notation:
Techniques for Numerical Integration
Basis of Mathematical Modeling LECTURE 3 Numerical Analysis with MATLAB Dr. N.K. Sakhnenko, PhD, Professor Associate.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Introduction to MATLAB 7 for Engineers William J. Palm.
Recap Functions with No input OR No output Determining The Number of Input and Output Arguments Local Variables Global Variables Creating ToolBox of Functions.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Part 5 Integration and Differentiation.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. A Concise Introduction to MATLAB ® William J. Palm III.
SE301_Topic 6Al-Amer20051 SE301:Numerical Methods Topic 6 Numerical Integration Dr. Samir Al-Amer Term 053.
EEE 242 Computer Tools for Electrical Engineering Lecture IV Mustafa KARABULUT.
Mathematical Applications By Matlab 3 rd Day Dr. Wael Khedr CSI Dept.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Chapter 20 Numerical Integration of Functions.
Numerical Integration
Trapezoidal Rule of Integration
Air Force Admin College, Coimbatore
ECE 1304 Introduction to Electrical and Computer Engineering
Introduction to Programming for Mechanical Engineers
Antiderivatives 5.1.
Antidifferentiation and Indefinite Integrals
Copyright © Cengage Learning. All rights reserved.
Numerical Analysis Lecture 43
Lecture: MATLAB Chapter 1 Introduction
Gauss Quadrature Rule of Integration
Chapter 7 Introduction to MATLAB for Engineers, Third Edition
Introduction to Programming for Mechanical Engineers (ME 319)
Integration Review Problems
MATLAB DENC 2533 ECADD LAB 9.
Symbolic mathematics: algebra ezplot calculus
Trapezoidal Rule of Integration
slides created by Marty Stepp
Tutorial 2 SEG7550 Introduction to MATLAB II
Gauss Quadrature Rule of Integration
Numerical Computation and Optimization
Simpson’s 1/3rd Rule of Integration
Simpson’s 1/3rd Rule of Integration
Air Force Admin College, Coimbatore
Presentation transcript:

Introduction to Programming for Mechanical Engineers (ME 319) Lecture 8.2: Symbolic Math Toolbox

Symbolic object Symbolic object or sym is a MATLAB data type. The ‘sym’ command lets you construct symbolic variables and expressions. x = sym('x') a = sym('alpha') Creates a symbolic variable x that prints as x and a symbolic variable a that prints as alpha. rho = sym('(1 + sqrt(5))/2') f = rho^2 - rho – 1 Note that both ‘rho’ and ‘f’ are not evaluated. They are just printed as a string representation. (simplify(f) evaluates it!)

Symbolic object f = sym('a*x^2 + b*x + c') Assigns the symbolic expression 𝑎 𝑥 2 +𝑏𝑥+𝑐 to the variable 𝑓. Does not create variables corresponding to the terms of the expression, 𝑎, 𝑏, 𝑐, and 𝑥. To perform symbolic math operations (e.g., integration, differentiation, substitution, etc.) on 𝑓, you need to create the variables explicitly. i.e. a = sym('a') b = sym('b') c = sym('c') x = sym('x') or simply syms a b c x Recommended to use ‘syms’ because it requires less typing.

MATLAB Command Example sym(t,'f') f-floating point >>t=0.1; sym(t,'f') ans = 3602879701896397/36028797018963968 sym(t,'r') or sym(t) r-rational >> sym(t,'r') 1/10 sym(t,'e') e-estimated error >> sym(t,'e') eps/40 + 1/10 sym(t,'d') d-decimal >> sym(t,'d') 0.10000000000000000555111512312578

Finding the Limits of a function- f(x) Mathematical Operation MATLAB Command lim 𝑥→0 𝑓(𝑥) limit(f) lim 𝑥→𝑎 𝑓(𝑥) limit(f,x,a) or limit(f,a) lim 𝑥→𝑎+ 𝑓(𝑥) limit(f,x,a,'right') lim 𝑥→𝑎− 𝑓(𝑥) limit(f,x,a,'left') Evaluate: (a) lim 𝑥→0 1 𝑥 (b) lim 𝑥→0+ 1 𝑥 (c) lim 𝑥→0− 1 𝑥

Finding the derivative of a function Mathematical Operation MATLAB Command 𝑦= sin 𝑎𝑥; 𝑑𝑦 𝑑𝑥 =? 𝑑𝑦 𝑑𝑎 = ? syms a x f = sin(a*x) diff(f) diff(f,a) 𝑑 2 𝑦 𝑑 𝑥 2 =? diff(f,2) or diff(f,x,2) Differentiation of a symbolic matrix – ‘A’ Performs element-wise differentiation A = [cos(a*x),sin(a*x);-sin(a*x),cos(a*x)] diff(A)

Finding the integral of a function Mathematical Operation MATLAB Command 𝑥 𝑛 𝑑𝑥= 𝑥 𝑛+1 𝑛+1 int(x^n) or int(x^n,x) 0 𝜋/2 sin 2𝑥 𝑑𝑥=1 int(sin(2*x),0,pi/2) or int(sin(2*x),x,0,pi/2) 𝑔= cos 𝑎𝑡+𝑏 𝑔 𝑡 𝑑𝑡= sin 𝑎𝑡+𝑏 𝑎 g = cos(a*t + b) int(g) or int(g,t) 𝐽 1 𝑧 𝑑𝑧=− 𝐽 0 (𝑧) int(besselj(1,z)) or int(besselj(1,z),z) All the variables that are used in indefinite integral should be defined as ‘syms’ (symbolic) variables

The integral of f(x) interpreted as the area A under the curve of f (x) from x = a to x = b.

Illustration of (a) rectangular and (b) trapezoidal numerical integration. Figure 9.1–1, page 370.

Numerical integration functions. Table 9.1–1, page 371. Command Description Example quad(fun,a,b) Uses an adaptive Simpson’s rule to compute the integral of the function whose handle is fun, with a as the lower integration limit and b as the upper limit. The function fun must accept a vector argument. Compute the integral of : 0 𝜋 𝑠𝑖𝑛 𝑥 𝑑𝑥 A=quad(@sin,0,pi) A=quadl(@sin,0,pi) quadl(fun,a,b) Uses Lobatto quadrature to compute the integral of the function fun. The rest of the syntax is identical to quad.

Numerical integration functions. Table 9.1–1, page 371 (Contd.) Command Description Example trapz(x,y) Uses trapezoidal integration to compute the integral of y with respect to x, where the array y contains the function values at the points contained in the array x. Although the ‘quad’ and ‘quadl’ functions are more accurate than ‘trapz’, they are restricted to computing the integrals of functions and cannot be used when the integrand is specified by a set of points. For such cases, use the trapz function.

Polynomial Integration q = polyint(p,C)returns a polynomial q representing the integral of polynomial p with a user-specified scalar constant of integration C. See page 375. Double Integrals A = dblquad(fun, a, b, c, d) computes the integral of f(x,y) from x = a to b, and y = c to d. Here is an example using an anonymous function to represent f(x,y) = xy2. 𝑥=𝑎 𝑏 𝑦=𝑐 𝑑 𝑥 𝑦 2 ⅆ𝑥ⅆ𝑦 >>fun = @(x,y)x.*y^2; >>A = dblquad(fun,1,3,0,1) The answer is A = 1.3333. For more, see pages 376 to 377.

Triple Integrals A = triplequad(fun, a, b, c, d, e, f) computes the triple integral of f(x, y, z) from x = a to b, y = c to d, and z = e to f. Here is an example using an anonymous function to represent f(x, y,z) = (xy - y2)/z. i.e. 𝑥=𝑎 𝑏 𝑦=𝑐 𝑑 𝑧=𝑒 𝑓 𝑥𝑦− 𝑦 2 𝑧 >>fun = @(x,y,z)(x*y –y^2)/z; >>A = triplequad(fun,1,3,0,2,1,2) The answer is A = 1.8484. Note that the function must accept a vector x, but scalar y and z. See page 377.

Bar Charts and Histograms Command Syntax Description Example bar(x,y) Creates a bar chart of y versus x. tests = 100; y=[91*ones(1,13),92*ones(1,15),93*ones(1,22),94*ones(1,19),95*ones(1,17),96*ones(1,14)]; x = [91:96]; [z,x] = hist(y,x); hist(y,x); figure; bar(x,z/tests); hist(y) Aggregates the data in the vector y into 10 bins evenly spaced between the minimum and maximum values in y. hist(y,n) Aggregates the data in the vector y into n bins evenly spaced between the minimum and maximum values in y. hist(y,x) Aggregates the data in the vector y into bins whose center locations are specified by the vector x. The bin widths are the distances between the centers.

Command Syntax Description [z,x] = hist(y) Same as hist(y) but returns two vectors z and x that contain the frequency count and the bin locations. [z,x] = hist(y,n) Same as hist(y,n) but returns two vectors z and x that contain the frequency count and the bin locations. [z,x] = hist(y,x) Same as hist(y,x) but returns two vectors z and x that contain the frequency count and the bin locations. The returned vector x is the same as the user-supplied vector x.

Thank you for the attention Any Questions and Suggestions please…