Chapter 12 Review: Symbolic Mathematics

Slides:



Advertisements
Similar presentations
Lecture 5.
Advertisements

Differential Equations Brannan Copyright © 2010 by John Wiley & Sons, Inc. All rights reserved. Chapter 08: Series Solutions of Second Order Linear Equations.
Beginning Programming for Engineers
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. A Concise Introduction to MATLAB ® William J. Palm III.
Matlab Graphics S. Awad, Ph.D. M. Corless, M.S.E.E. E.C.E. Department University of Michigan-Dearborn Introduction to Matlab: 2D Graphics.
Chapter 11: Symbolic Computing for Calculus
Calculus S. Awad, Ph.D. M. Corless, M.S.E.E. E.C.E. Department University of Michigan-Dearborn Math Review with Matlab: Differentiation.
CSE 123 Symbolic Processing. Declaring Symbolic Variables and Constants To enable symbolic processing, the variables and constants involved must first.
MATLAB FUNDAMENTALS: USER DEFINED FUNCTIONS THE SYMBOLIC TOOLBOX HP 100 – MATLAB Wednesday, 10/29/2014
Introduction to C Programming
Lecture 16 Symbolic Mathematics Symbolic mathematics: algebraezplotcalculus © 2007 Daniel Valentine. All rights reserved. Published by Elsevier.
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.
 2007 Pearson Education, Inc. All rights reserved Introduction to C Programming.
The Islamic University of Gaza Faculty of Engineering Numerical Analysis ECIV 3306 Introduction.
Differential Equations
LINEAR EQUATIONS IN TWO VARIABLES. System of equations or simultaneous equations – System of equations or simultaneous equations – A pair of linear.
LINEAR EQUATION IN TWO VARIABLES. System of equations or simultaneous equations – System of equations or simultaneous equations – A pair of linear equations.
8.5 Series Solutions Near a Regular Singular Point, Part I
3.1 Derivative of a Function
Differential Equations
Unit 2 Logarithms
Real Numbers and Algebra
Computer Science 1000 Spreadsheets II Permission to redistribute these slides is strictly prohibited without permission.
Copyright © Cengage Learning. All rights reserved. 7 Techniques of Integration.
Chapter 10 Review: Matrix Algebra
Chapter 5 Review: Plotting Introduction to MATLAB 7 Engineering 161.
BY PARTS. Integration by Parts Although integration by parts is used most of the time on products of the form described above, it is sometimes effective.
259 Lecture 18 The Symbolic Toolbox. 2  MATLAB has a set of built-in commands that allow us to work with functions in a fashion similar to Mathematica.
Simultaneous Equations By Dr J.P.M. Whitty
ECE 1304 Introduction to Electrical and Computer Engineering Section 1.1 Introduction to MATLAB.
5.4 Exponential Functions: Differentiation and Integration.
Numerical Computation Lecture 2: Introduction to Matlab Programming United International College.
MATLAB Basics. The following screen will appear when you start up Matlab. All of the commands that will be discussed should be typed at the >> prompt.
Chapter 2: First Steps in MuPAD MATLAB for Scientist and Engineers Using Symbolic Toolbox.
Copyright © Cengage Learning. All rights reserved. 4 Quadratic Functions.
Analytical Toolbox Differential calculus By Dr J.P.M. Whitty.
Integrals  In Chapter 2, we used the tangent and velocity problems to introduce the derivative—the central idea in differential calculus.  In much the.
Introduction To this point MATLAB has been used to answer questions with a numeric value ▫Variables are assigned specific values ▫Answers are numbers MATLAB.
10/24/20151 Chapter 2 Review: MATLAB Environment Introduction to MATLAB 7 Engineering 161.
MATLAB Harri Saarnisaari, Part of Simulations and Tools for Telecommunication Course.
Equations, Inequalities, and Mathematical Models 1.2 Linear Equations
MATHLAB Prepared for: Md. Monzur Ashraf Prepared By: Md. Shafiul Parvez Aakaash.
Recap Sum and Product Functions Matrix Size Function Variance and Standard Deviation Random Numbers Complex Numbers.
Scientific Computing Introduction to Matlab Programming.
Introduction to Matlab
Chapter 6 Review: User Defined Functions Introduction to MATLAB 7 Engineering 161.
Numerical Methods.
Unit 0 Lessons 1-3 Evaluating expressions using order of operations By R. Portteus and By Miss Klien modified by LHope.
MATLAB Jirawat Kanjanapitak (Tae). What is MATLAB A computer program for doing numerical computation including; Arithmetic, Polynomials, Graphics, 2-D.
Lecture 1: Matlab Universe
Analytical Toolbox Integral CalculusBy Dr J.P.M. Whitty.
Analytical Toolbox Introduction to arithmetic & algebra By Dr J. Whitty.
Previous Page Next Page EXIT Created by Professor James A. Sinclair, Ph.D. MMXI Monomials, binomials, and Polynomials Monomials, binomials, and polynomials.
Advanced Engineering Mathematics, 7 th Edition Peter V. O’Neil © 2012 Cengage Learning Engineering. All Rights Reserved. CHAPTER 4 Series Solutions.
In Chapters 6 and 8, we will see how to use the integral to solve problems concerning:  Volumes  Lengths of curves  Population predictions  Cardiac.
ERT 210/4 Process Control & Dynamics DYNAMIC BEHAVIOR OF PROCESSES :
Solving Exponential and Logarithmic Equations Section 3.4.
EEE 242 Computer Tools for Electrical Engineering Lecture IV Mustafa KARABULUT.
5.1 Exponential Functions
Copyright © Cengage Learning. All rights reserved.
Symbolic Mathematics Chapter 12
259 Lecture 18 The Symbolic Toolbox.
ECE 1304 Introduction to Electrical and Computer Engineering
Other Kinds of Arrays Chapter 11
INTRODUCTION TO BASIC MATLAB
MATLAB DENC 2533 ECADD LAB 9.
Symbolic mathematics: algebra ezplot calculus
Introduction to the C Language
Class Notes 9: Power Series (1/3)
Chapter 3 Modeling in the Time Domain
Presentation transcript:

Chapter 12 Review: Symbolic Mathematics Introduction to MATLAB 7 Engineering 161

Symbolic Mathematics In MATLAB we can use symbols to perform mathematical computations as well as numbers. These features are contained in the Symbolic Math Toolbox. They are based upon Maple 8 a software package published by Waterloo Maple, Inc. We will learn how to define expressions symbolically and then manipulate them with MATLAB functions. Symbolic manipulations are often very useful in engineering problem solving and compliments solutions to problems with numbers.

Symbolic Mathematics II After studying the material in Chapter 11 you should be able to Create and manipulate symbolic variables Factor and simplify mathematical expressions Solve symbolic expressions Determine the symbolic derivative of an expression and integrate an expression.

An Example Before jumping into the details, look at some simple examples, >> a = sym (‘x - 2’); % a and b are sym variables, they are >> b = sym (‘2*x + 3’); % strings of characters >> y = a*b % y is another string of characters y = (x-2)*(2*x+3) >> expand(y) ans = 2*x^2 - x - 6

Another Example Consider another example, >> S = sym(‘(x^2 - 3*x – 10)/(x + 2)’); >> simplify(S) ans = x – 5 Note that the symbolic expression is defined by the sym function, the argument of the sym function is a string of characters defining the expression symbolically enclosed in single quotes.

One More Example Suppose you want to solve the equation D = D0*exp(-Q/RT) for Q. This equation describes the rate of diffusion, see section 11.1 in the text. >>X = sym(‘D=D0*exp(-Q/RT)’); >>solve (X,’Q’) % Q is in single quotes to tell MATLAB ans = % that it is a symbol -log(D/D0)*RT Note in MATLAB log represents the natural logarithm, normally written as ln in mathematics, log10 represents the logarithm to the base 10 and log2 represents the logarithm to the base 2.

Defining Symbolic Expressions and Variables There are two methods, Either create the complex symbolic expression all at once using the sym command as we did in the examples, Or, use the syms command to list all the symbolic variables individually and then compose the expression using algebraic operators like, * or + and -, etc. >> syms a x y; >>S = x^2 -2*y^2 + 3*a; These two MATLAB statements define the variables a, x, and y as symbolic variables, and then creates the symbolic expression S. Note that in the first case using the sym function, only S would appear in the Workspace Window, while in the second case, S, a, x, and y all appear in the Workspace Window.

Plotting Symbolic Expressions MATLAB provides an easy way to plot symbolic expressions of a single variable, it is called ezplot. Suppose S is a symbolic expression of x, then >>ezplot(S, [xmin, xmax]) will plot S between the limits of xmin and xmax. >> ezplot(S) always uses the range [-2 *pi, 2*pi] You can use the commands xlabel, ylabel, and title to add x and y labels, etc., in the usual way. Also use grid on, hold on and hold off, subplots, etc.

Plotting Symbolic Expressions II MATLAB provides a number of built in symbolic plotting functions in addition to ezplot. They are described in Table 11.3 and some of them are illustrated on pages 400-401. Do the practice exercise 11.7 on page 402 to gain some experience with the variety of symbolic plotting functions. Remember you can use xlabel, ylabel, title, hold on and off, and subplots just as you have used them before with the basic plotting function plot(x,y)

Let’s look at another example Consider the golden ratio, >> y = sym(‘(1 + sqrt(5))/2’); >> f = y^2 – y - 1 f = (1/2 + 1/2*5^(1/2))^2-3/2-1/2*5^(1/2) >>simplify(f) y is a symbolic expression that we manipulate in the first and second MATLAB statements.

A Matrix Example Consider the following matrix example, >>syms a b c d; >>A = [a b c; a b c; a b c] A = [ a, b, c] >>sum(A(1,:)) ans = a+b+c >>sum(A(:,2)) b+b+b

A Matrix Example II Matrix multiplication symbolically, >> A = [a b; c d]; >> A^2 ans = [ a*a+b*c, a*b+b*d] [ c*a+d*c, c*b+d*d] Note here that a, b, c and d were already declared as symbols in the previous example and hence would be in the Workspace Window as symbols. No need to redefine them for this second example. Try taking the inverse of A using the inv function.

Some Symbolic Functions There are a number of functions used to manipulate and simplify symbolic expressions, collect(S) collects coefficients of S expand(S) expands S where possible factor(S) returns the factors of S where possible simplify(S) simplifies S using Maple’s rules simple(S) returns a number of potential simpler forms poly2sym(V) creates a symbolic expression for the polynomial described by the vector V >>V = [ 1 -4 0 2 45]; >> S = poly2sym(V) S = x^4 - 4*x^3 + 2*x + 45 What do you think V = sym2poly(S) does?

Some Symbolic Functions II Continuing, solve(f) solves the symbolic equation f for its symbolic variable; if more than one, then for x, sets f = 0 and solves for x. solve(f, ‘y’) solves f(x,y) for y; you don’t need the quotes if y has been declared as a symbolic variable solve(f1,…,fn) solves a system of equations Let’s look further into this last function.

Solve Function When used with an expression, the solve function sets the expression to zero and solves for its roots For example, E1 = x – 3, solve(E1) would yield the answer ans = 3. One could also have said solve(x-3), that put the expression inside the parenthesis. The solve function normally solves for x, if you want to solve for a different variable, then solve(f, t) for example would solve for t. Even when the result of the solve function is a number, it is still stored as a symbolic variable and needs to be converted to be used in an arithmetic expression, use the double function.

Substitution: the subs function Once you have a symbolic expression, you may want to substitute values into it, we use the subs function. Consider, syms a b c x; f = a*x^2 + b*x + c; g = subs(f, a, 3) g = 3*x^2 + b*x + c

Substitution II h = subs(f, {a, b, c}, {1, 2, 3}) h = x^2 + 2*x + 3 subs(h, x, -2) ans = 3

Substitution III Substituting an expression, consider from Example 11.2, syms v0 t g theta; distancex = v0 * t * cos(theta); impact_time = 2 * v0 * sin(theta)/g; impact_distance = subs(distancex, t, impact_time) impact_distance = 2 * v0^2 * sin(theta)/g * cos(theta)

Solving Simultaneous Equations Suppose we have the following, >>eq1 = sym (‘3*x + 2*y - z = 10’); >>eq2 = sym (‘-x + 3*y + 2*z = 5’); >>eq3 = sym (‘x – y – z = -1’); >>[A, B, C] = solve (eq1, eq2, eq3) A = -2 B = 5 C = -6 Note the symbols assigned to A, B, and C are assigned alphabetically based upon the order of the variable names in the equations, eq1, eq2, eq3.

Solving Simultaneous Equations Again II Now remember, if you want to use A, B, and C in some subsequent numerical expression, you will have to convert them to numbers, (A, B, and C have character representations from the solve operation.) To do this, do the following; >> a = double(A), b = double(B), c =double(C); this double function converts characters to real numbers. Now a, b, and c have numerical variables assigned to them. To avoid confusion, watch your Workspace window for the declarations of the variables as they are created. Characters have the <1x1sym> designation while real numbers are designated as double typically.

Calculus MATLAB’s symbolic toolbox allows users to differentiate symbolically and to perform integrations. This makes it possible to find analytical solutions (expressions), instead of numeric approximations for many problems. We will look at differentiation integration solving simple differential equations Let’s start by looking at an example where we’ll use the int (integration) function to solve a basic problem.

Another Example: Water Flow (11.32) Water is being pumped into an initially empty tank. It is known that the rate of flow of water into the tank at time t (seconds) is (50 – t) liters/sec. The amount of water Q that flows into the tank during the first x seconds can be shown to be equal to the integral of the expression (50 – t) evaluated from 0 to x seconds. Determine a symbolic equation that represents the amount of water in the tank after x seconds. Determine the amount of water in the tank after 30 seconds. Determine the amount of water that flowed into the tank between 10 and 15 seconds after the flow was initiated.

Water Flow II Consider the following sequence of MATLAB statements; >> f = sym (’50 – t’) % create the symbolic variable f = 50 - t f = 50 – t >>Q = int (f, 0, ‘x’) % integrate f(t) between ‘0’ and ‘x’ seconds Q = 50*x – 1/2*x^2 >>Q = int (f, 0, 30) % integrate f(t) between 0 and 30 seconds 1050 >>Q = int (f, 10, 15) % integrate f(t) between 10 and 15 seconds 375/2

Differentiation The diff function is used to determine the symbolic derivative of a symbolic expression f. diff(f) returns the derivative of f w.r.t. the default independent variable diff(f, ‘t’) returns the derivative of f w.r.t. the variable t diff(f, n) returns the nth derivative of f w.r.t the diff(f, ‘t’, n) returns the nth derivative of f w.r.t the We look at the example in our book in section 11.4.1, pg 419

The Drag Racer Consider a drag racer that starts from rest, accelerates to the finish line and then decelerates back to rest. The total distance travelled is given by the following expression; d = 20 + 20 sin (p(t – 10)/20) Let’s use MATLAB to plot the function d vs t for 0 < t < 20 seconds, determine and plot the velocity and acceleration of the drag racer and determine the maximum velocity of the car. The car crossed the finish line at t = 10 seconds when it starts to decelerate.

The Drag Racer II Consider the following MATLAB statements; syms t; d = 20 + 20*sin(pi*(t – 10)/20); ezplot(d, [0,20]); vel = diff(d); figure(2); ezplot(vel, [0,20]);

The Drag Racer III Continuing, accel = diff(vel); figure(3); ezplot(accel, [0,20]); d % outputs the expression for d vel % outputs the expression for vel accel % outputs the expression for accel

The Drag Racer IV Continuing, The maximum velocity is determined by setting the derivative of the velocity to zero and solving for t. Since accel is the derivative of vel, we have that max_vel = solve(accel)

Integration MATLAB supports the following symbolic integration capabilities; the int function attempts to find a function F such that diff(F) = f; diff(F) being the derivative of F. int(f) returns the integral of the expression f w.r.t. the independent variable int(f, ‘t’) returns the integral of f w.r.t. the variable t int(f, a, b) returns the integral of f w.r.t. the independent variable over the interval [a,b]; a and b numerical int(f, ‘t’, a, b) returns the integral of f w.r.t to t over the interval [a,b]; a and b numerical Int(f, ‘m’, ‘n’) returns the integal of f w.r.t. the independent variable over the interval [m,n] where m and n are symbolic expressions.

Differential Equations MATLAB’s symbolic toolbox provides capabilities to solve differential equations. To review these capabilities use the help dsolve command in the Command Window. dsolve is the function that you will want to explore. Use the MATLAB help features. Consider the following, Suppose we have the equation dx/dt = -a*x and we want to solve for x >>dsolve(‘Dx = - a*x’) ans = C1*exp(-a*t) % note the undetermined constant C1 >>dsolve(‘Dx = -a*x’, ‘x(0) = 2’) % with the initial condition specified 2*exp(-a*t) % pretty cool

Chapter 11 Assignment These assignments will give you some practice with the concepts in Chapter 11. Assignments 12.7, 12.9 and 12.10, 12.11, 12.15, 12.16, 12.29, 12.30.