75922978-MATH15L-Coursewares - in cooperation with presents...

This preview shows page 1 out of 215 pages.

Unformatted text preview: in cooperation with presents Course Code: MATH15L Course Title: MATLAB Pre-requisite: Co-requisite: MATH 15 Credit: 1 unit Equivalent Course Codes: None Faculty: Course Description The course utilizes the capability of information technology to facilitate the understanding of basic mathematical principles and operations. A mathematical software (MATLAB) will be used to perform algebraic operations, differentiation, integration, matrix operations, graphic manipulation and some basic MATLAB programming for simulations and analysis. Course Objectives and Relationship to Program Objectives It is a laboratory course in mathematics. Its goals are to give the students sufficient understanding of MATLAB and its application for the purpose of developing students¶ skill in solving problems and to apply their acquired learning in engineering applications. It prepares students to recognize patterns and formulate rules as a first step to develop students¶ skill for independent critical thinking. The course aims to develop the students¶ zest for knowledge, application and appreciation of an orderly and logical solution as guided by the different principles undertaken in the course. Course Coverage Foundation and Fundamental Concepts Arrays and Matrices Symbolic Math Graphs Programming Course Outcomes and Relationship to Program Outcomes: A student completing this course should at a minimum be able to: perform polynomial operations such as multiplication and division. decompose rational polynomials into sum of partial fractions. perform the four fundamental operations on matrices as well as getting the determinant of square matrix. solve systems of equations and polynomial equations. perform differentiation and integration. plot the graphs of lines, circles, ellipses, parabolas and hyperbolas. plot the graphs of polynomial functions and transcendental functions. compile a simple MATLAB program. Course Evaluation Points Long Tests 2 250 25% Classroom Exercise/Hands on Exam Classroom Participation 5 450 45% Portfolio 1 50 5% Final Examination 1 250 25% 1000 100% TOTAL Long Test/Classroom Exercise/ Hands on Exam/Final Exam Guidelines No borrowing of terminal/ terminal account. Use black ballpen/tech-pen. Show your answers clearly. Use short white/bond paper. Avoid going out during examination. No special exam. Portfolio Guidelines No late Portfolio will be accepted. Use short black Clear Book. Average Grade Average Grade Below 70 5.00 83.21-86.5 2.00 70-73.3 3.00 86.51-89.8 1.75 73.31-76.6 2.75 89.81-93.1 1.50 76.61-79.9 2.50 93.11-96.4 1.25 79.91-83.2 2.25 96.41-100 1.00 Other course Policies Attendance According to CHED policy, total number of absences by the students should not be more than 20% of the total number of meetings or 9 hrs for this one-unit-course. Student incurring more than 9 hours of absences automatically gets a failing grade regardless of class standing. Honor, Dress and Grooming Codes All of us have been instructed on the Dress and Grooming Codes of the Institute. We have all committed to obey and sustain these codes. It will be expected in this class that each of us will honor the commitments that we have made. For this course the Honor Code is that there will be no plagiarizing on written work and no cheating on exams. If a student is caught on two exams, the student will be referred to the Prefect of Student Affairs and given a failing grade. Consultation Schedule Consultation schedules with the Professor are posted outside the Mathematics Faculty Room. It is recommended that the student first set an appointment to confirm the instructor¶s availability if outside the consultation schedules. Computer Laboratory Guidelines No student shall be allowed to enter the laboratory without his or her Instructor. EATING, DRINKING, LITTERING and VANDALISM in any form are strictly prohibited. All belongings shall place in the designated areas. Valuables and important belongings should be brought in. The assigned personnel is not liable for any loses or damages that would occur. A strict one (1) computer to one (1) student ratio shall be observed. Students are not allowed to use external devices without the approval of the Deputy Director for Systems Administration. Students must notify the assign personnel in charge regarding any errors and/or breakages of facilities and/or equipment in their designated areas. No excessive noise. Using mobile phone or any musical instrument is strictly prohibited. Diskettes are not allowed. Accessing the internet is prohibited. MATLAB BASICS What is MATLAB? - The name stands for MATrix LABoratory - MATLAB is a high-performance language for technical computing. It integrates computation, visualization, and programming environment. - MATLAB is a modern programming language environment: it has sophisticated data structures, contains built-in editing and debugging tools, and supports object-oriented programming. THE MATLAB SYSTEM - Development Environment The MATLAB Mathematical Function Library The MATLAB Language The MATLAB Application Program Interface (API) Development Environment - Set of tools and facilities that help use MATLAB functions and files. - Includes: - MATLAB Desktop - Command Window - Command History - Editor and Debugger and browsers for viewing help - Workspace MATLAB MATHEMATICAL FUNCTION LIBRARY - This is a vast collection of computational algorithms ranging from elementary functions Examples: > sum, sine, cosine, and complex arithmetic > sophisticated functions like matrix inverse, matrix eigenvalues, Bessel functions, and fast Fourier transforms. MATLAB LANGUAGE - This is a high-level matrix/array language with control flow statements, functions, data structures, input/output, and object-oriented programming features. - It allows both "programming in the small" to rapidly create quick and dirty throw-away programs, and "programming in the large" to create complete large and complex application programs. GRAPHICS - MATLAB has extensive facilities for displaying vectors and matrices as graphs, as well as annotating and printing these graphs. - It includes high-level functions for two-dimensional and three-dimensional data visualization, image processing, animation, and presentation graphics. - It also includes low-level functions. MATLAB APPLICATION PROGRAM INTERFACE - This is a library that allows you to write C and Fortran programs that interact with MATLAB. - It includes facilities for calling routines from MATLAB (dynamic linking), calling MATLAB as a computational engine, and for reading and writing MAT-files. Development Environment Desktop Tools - Command Window Command History Star Button and Launch Pad Help Browser Current Directory Browser Workspace Browser Array Editor Editor/Debugger Profiler WORKSPACE BROWSER - Consists of the set of variables during a MATLAB session and stored in memory ARRAY EDITOR - Use to edit the variables in the workspace. - Three ways to open: double click the variable in the workspace browser, select the variable in the workspace and click open , use the openvar syntax EDITOR/DEBUGGER - Used to create and debug M-files, which are program you write to run the MATLAB functions Foundation and Fundamental Concepts Entering Commands and Expressions ‡ The prompt >> is displayed in the Command Window and when the Command Window is active, a blinking cursor should appear to the right of the prompt. ‡ This cursor and the MATLAB prompt signify that MATLAB is waiting to perform a mathematical operation. Commands for Managing a Session clear who - Removes all the variables from the workspace. - Frees up system memory - Displays the list of variables currently in the memory. exist - Will display more details which include size, space, allocation and class of variables - Checks for existence of the variable. global help - Declares variable to be global. - Searches for help topic lookfor quit - Searches help entries for keyword - Stops the MATLAB whos Help Features in MATLAB helpbrowser Opens the help window Displays the help document in the help function_name command window Displays the help document in helpwin function_name separate window doc function_name Displays detailed help document in separate window Numeric Display Formats - Controls the display output of the command window Common Format Functions format short long - Four decimal digits - Sixteen decimal digits short e long e - Five decimal digits plus exponent - Sixteen digits plus exponent bank - Two decimal digits Mathematical Functions Special Variables and Constants ans - Most recent answer i,j Inf - The imaginary unit - Infinity NaN pi - Undefined numerical result (not a number) - The number Mathematical Functions Elementary Functions cos(x) Cosine abs(x) Absolute value sin(x) Sine ceil(x) Round towards + Inf tan(x) Tangent floor(x) Round towards - Inf acos(x) Arc cosine round(x) Round asin(x) Arc sine rem(x) Remainder after division atan(x) Arc tangent angle(x) Phase exp(x) Exponential conj(x) Complex Conjugate sqrt(x) Square root imag (x) imaginary log(x) Natural Logarithm real (x) Real number log10(x) Common Logarithm primes (x) Prime Number Mathematical Functions Scalar Arithmetic Symbol Operation + Addition - Subtraction * Multiplication / Right Division \ Left Division ^ Exponentiation Mathematical Functions Exponential and Logarithmic Functions exponential exp (x) Natural Logarithm ln (x) Common Logarithm log10 (x) = [ log10 (x) ] Square root sqrt (x) Example1: 2+3±4 In Command Window >>2 + 3 ± 4 ans = 1 Example2: 6z3 In Command Window >> 6 / 3 ans = 2 Example3: 3z6 In Command Window >> 6 \ 3 ans = 0.5 ‡ MATLAB has assigned the answer to a variable called ans, which is an abbreviation for answer. A variable in MATLAB is a symbol used to contain a value. ‡ MATLAB does not care about spaces for the most part. Spaces in the line improve its readability. ‡ When you want to calculate a more complex expression use parentheses, in the usual way, to indicate precedence. ‡ The mathematical operations represented by the symbols + ± * / \, and ^ follow a set of rules called precedence.. ‡ Mathematical expressions are evaluated starting from the left, with the exponentiation operation having the highest order of precedence, followed by multiplication and division with equal precedence, followed by addition and subtraction with equal precedence. ‡ Parentheses can be used to alter this order. Evaluation begins with the innermost pair of parentheses, and proceeds outward. ‡ To avoid mistakes, you should feel free to insert parentheses wherever you are unsure of the effect precedence will have on the calculation. Example4: 4 3(23  14 .7  ) 6 3 .5 In Command Window >> (3*(23 + 14.7 ± (4 / 6))) / 3.5 Naming constants and variables ‡ MATLAB allows us to give constants and variables names of our choice. This is a powerful facility that can reduce work and help in avoiding input errors. ‡ When the user begins a session in which the same values must be used several times, the user can define them once and then call them by name. Example5: Given: a = 2, A = 3 Find: a. 2a b. w=3A In Command Window >>a=2 a= 2 >>A=3; ‡ When you write the semicolon µ ; µ at the end of a statement, the computer will not display the result of the command, and it will not echo the input. >>2*a ans = 4 >>w=3*A w= 9 ‡ MATLAB does not tell you the value of all the variables; it merely gives you their names. To find their values, you must enter their names at the MATLAB prompt. >>a = 4 a= 4 >>2*a ans = 8 ‡ If you reuse a variable in the preceding example, or assign a value to one of the special variables, its prior value is overwritten and lost. However, any other expressions computed using the prior value do not change. Example6: Given: E = 30, F = 52, K = 76 Find: a. Sin E b. Sin F c. Sin K In Command Window >> alpha = 30; >> beta = 52; >> gamma = 76; >> sin (alpha) ans = ±0.9880 ‡ A pair of parentheses is used after the function¶s name to enclose the value ± called the function¶s argument ± that is operated on by the function. >> sin (beta) ans = 0.9866 >> sin (gamma) ans = 0.5661 ‡ MATLAB remembered past information. ‡ To recall previous commands, MATLAB uses the cursor keys, n, o, p, q, on your keyboard. ‡ In addition, all text after a percent sign (%) is taken as a comment statement. Example of Formating: T or pi In Command Window >> pi ans = 3.1416 ‡ MATLAB uses high precision for its computations, but by default it usually displays its results using four decimal places. This is called the short format. Using the format command can change this default. >> format long >> pi ans = 3.14159265358979 ‡ MATLAB uses the notation e to represent exponentiation to a power of 10. >> format short e >> pi ans = 3.1416e+000 >> format long e >> pi ans = 3.14159265358979e+000 >> format bank >> pi ans = 3.14 To return to default format >> format >> pi ans = 3.1416 ‡ Most interesting is the format rat: it yields a rational approximation of a real number, that is a fraction that approximates a given number. >> format rat >>pi ans = 355/113 >>format >>355/113 ans = 3.1416 Practice Set: 1. Perform the indicated operation: a. 2{± 4 ± [6 + 3 + (7 ±(1 + 8)) + 12] ± 3} + 5 b. ±5{± [± 2 + 6 ± 8(4 ± (7 ± 4) ± 2) + 2] ± 1} c.  3( 2)  3  12  3(2) d 58 8  ( 4) z 4  ( 2) 25 e. Given: 5T x! 2 Determine: i. y = sin x ii. when y = 1, what is z = sin-1 y cos1 0.3 g. e h. cos (T / 2) 2. Suppose that x = 3 and y = 4. Use MATLAB to compute the following. ¨ 1¸ a. ©1  5¹ ª xº 1 b. 3 T3 y x2 c. 4 x  8 d. 4( y  5 ) 3x  6 3. Assuming that the variables a, b, c, d and f are scalars, write MATLAB statements to compute and display the following expressions. Test your statements for the values a = 1.12, b = 2.34, c = 0.72, d = 0.81, f = 19.83 a. ac x ! 1 b. b  ba s! dc f 2 c. r ! 4. 1 1111  abcd d. 2 1f y ! ab c2 Evaluate the following expressions MATLAB, for the values x = 5 + 8i, y = ± 6 + 7i. a. u = x + y b. v = xy c. w = x / y d. z = ex e. r ! y f. s = xy2 in Polynomial Algebra Partial fraction Roots of Equation Polynomial and Symbolic Conversion Consider f(x) = 12x4 ± 3x2 + x + 7. This function f can be written in array form called coefficient array, that is, f = [12, 0, -3, 1, 7]. Command conv(a, b) Description Computes the product of the two polynomials described by the coefficient arrays a and b. The two polynomials need not be the same degree. The result is the coefficient array of the product polynomial. Example 1. (2x+1)(3x-5) Answer 6x^2 -7x -5 2. (x^2-3)(x^3+2x+1) X^5-x^3+x^26x-3 [q, r] = deconv(num, den) Example Computes the result of dividing a numerator polynomial, whose coefficient array is num, by a denominator polynomial represented by the coefficient array den. Answer Q= 4x+11  2x  3 R= 59x ± 41 12x  5 x 2 3x  7 x  4 3 2 2x  x  6 x 2 2x  7 x  6 3 2 Q= x+3 R= 9x -18 poly(r) Computes the coefficients of the polynomial whose roots are specified by the vector r. The result is a row vector that contains the polynomial¶s coefficients arranged in descending order of power Example Answer X1=1 X2=-1 10 X1=1 X2=2 X3=3 1 -6 -1 => X^2-1 11 -6 => x^3-6x^2+11x-6 [r,p,k] = residue(a,b) Finds the residues, poles and direct term of a partial fraction expansion of the ratio polynomials a(x) / b(x) Example Answer 5x  7 3 2 x  x x2 2x  4x  2x  x  7 x3  2 x 2  x  2 4 3 2 2 1 1   x 1 x 1 x  2 2 1 1 2x    x 1 x 1 x  2 polyval(a, x) Evaluates a polynomial at specified values of its independent variable x, which can be a matrix or a vector. The polynomial¶s coefficients of descending powers are stored in the array a. Example Answer 1. f(x)=x^2-x+5. Find f(2) 7 roots(a) Computes the roots of a polynomial specified by the coefficient array a. The result is a column vector that contains the polynomial¶s roots. Example X^2-1 Answer X1=1 X2=-1 X1=1 X2=2 X3=3 x^3-6x^2 +11x-6 sym2poly Convert a symbolic polynomial to polynomial coefficient vector Example: sym2poly(x^3 - 2*x - 5) returns [1 0 -2 -5] poly2sym Convert a polynomial coefficient vector to symbolic polynomial Example: poly2sym([1 0 -2 -5]) is x^3-2*x-5 SYMBOLIC PROCESSING ‡ Process of obtaining answers in the form of expressions ‡ Terms used to describe how MATLAB performs operations or evaluates mathematical expressions in the way, for examples, that humans do algebra with pencil and paper. Symbolic Object Symbolic object is a data structure that stores a string representation of the symbol. The two ways to create symbolic object are: 1. Using sym function Typing x = sym(µx¶) creates the symbolic variable with name x. 2. Using syms command syms x is equivalent to typing x = sym(µx¶). Typing syms x y z creates three symbolic variables x, y and z. Symbolic Constants: To create symbolic constant, use the sym function. >> pi = sym(µpi¶) >> fraction = sym(µ1/4¶) >> sqroot2 = sym(µsqrt(2)¶) Symbolic Variables & Expressions The sequence of commands >> syms x y x >> m = sqrt (x ^2 + y^2 + z^2) >> n = sin (x*y) / (x*y) generates the symbolic m and n. Symbolic Constants: To create symbolic constant, use the sym function. >> pi = sym(µpi¶) >> fraction = sym(µ1/4¶) >> sqroot2 = sym(µsqrt(2)¶) Symbolic Variables & Expressions The sequence of commands >> syms x y x >> m = sqrt (x ^2 + y^2 + z^2) >> n = sin (x*y) / (x*y) generates the symbolic m and n. Symbolic objects can be classified as: 1. symbolic variable (ex. x, y, z) 2. symbolic constant (ex. pi, sqrt(3)) 3. symbolic expression (ex. x^2 + y^2) 4. symbolic matrix (ex. [a, b, c; b, c, a; c, a, b] To create symbolic constant, use the sym function. Example: >> pi = sym(µpi¶) >> fraction = sym(µ1/4¶) >> sqroot2 = sym(µsqrt(2)¶) pretty The pretty function displays symbolic output in a format that resembles typeset mathematics. Syntax: pretty (S) >>m = sqrt (x^2 + y^2 + z^2) m= (x^2+y^2+z^2)^(1/2) >> pretty (m) 2 2 2 1/2 (x + y + z ) Examples: >> f = x^3-6*x^2+11*x-6 >> g= (x-1) * (x-2)* (x-3) >> pretty (f) >> pretty (g) Or >> pretty (x^3-6*x^2+11*x-6) >> pretty ((x-1) * (x-2)* (x-3)) double The statement double (s) converts the symbolic object S to a numeric object. Syntax: r = double (S) >> sqroot2 = sym (µsqrt (2)¶); >> z = 6* sqroot2 >> double (z) SIMPLIFICATION: Commands collect (s) expand (s) horner (s) factor (s) simplify (s) simple (s) collect collect (f) ± views f as a polynomial in its symbolic variables, say x, and collects all the coefficients with the same power of x. Syntax: collect (S) Ex. 1. H =x[x(x-6)+11]-6 >> h = x * (x *(x-6)+11)-6 collect (h) ans = x^3-6*x^2+11*x-6 Syntax : collect (S, µx¶) ± the 2nd argument can specify the variable in which to collect terms if there is more than one candidate. expand expand (f) ± distributes products over sums and applies other identities involving transcendental functions. Syntax: expand (S) Ex. 1. (x-2)(x-3)(x-5) 2. cos (x+y) 3. e a+b horner horner (f) ± transforms a sumbolic polynomial f into its Horner, (or nested, representation) Syntax: horner (f) Ex. 1. (x3 ± 3x2 ± 4x +5) 2. 2x5 ± x4 + 3x2 ± 4x +5 3. 1.1 + 2.2x + 3.3x2 factor factor (S) ± factors the expression S which can be positive integer, an array of symbolic expressions, or an array of symbolic integers. Syntax: factor (S) Ex. 1. factor (x^3 - y^3) simplify simplify (E) ± simplify the expression E using Maple¶s simplification rules. Ex. >> simplify (sin (x)^2+cos(x)^2) ans 1 1. 1- x2 1 ±x simplify ((1-x^2)/(1-x)) ans = x+1 simple simple(E) ± searches for the symbolic expression¶s simplest form; that is, an expression that has the fewest character. Syntax: r = simple (S) Ex. Apply the simple and simplify commands 1. log (xy) 2. cos (3cos-1(x)) 3. (x+1)(x)(x-1) Substitution subs ± used for symbolic substitution in a symbolic expression or matrix Syntax: R = subs (S, old, new) Ex. Given f(x) = x3+4x2-3x+5 Find: 1. f(4) 2. f(2z) 3. f(x+1) Solving Equations If S is a symbolic expression solve (S) attempts to find values of the symbolic variable is S for which S is zero Syntax: g = solve (eq) g = solve (...
View Full Document

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture