MATLAB Commands and Functions



Similar documents
MATLAB LECTURE NOTES. Dr. ADİL YÜCEL. Istanbul Technical University Department of Mechanical Engineering

MATLAB Basics MATLAB numbers and numeric formats

Higher Education Math Placement

Algebra and Geometry Review (61 topics, no due date)

Introduction to MATLAB

MatLab Basics. Now, press return to see what Matlab has stored as your variable x. You should see:

Georgia Department of Education Kathy Cox, State Superintendent of Schools 7/19/2005 All Rights Reserved 1

Function Name Algebra. Parent Function. Characteristics. Harold s Parent Functions Cheat Sheet 28 December 2015

Engineering Problem Solving and Excel. EGN 1006 Introduction to Engineering

How To Use Matlab

Prentice Hall Mathematics: Algebra Correlated to: Utah Core Curriculum for Math, Intermediate Algebra (Secondary)

2+2 Just type and press enter and the answer comes up ans = 4

South Carolina College- and Career-Ready (SCCCR) Pre-Calculus

User Guide.

u = [ 2 4 5] has one row with three components (a 3 v = [2 4 5] has three rows separated by semicolons (a 3 w = 2:5 generates the row vector w = [ 2 3

Introductory Course to Matlab with Financial Case Studies

Introduction to Matlab

MATH BOOK OF PROBLEMS SERIES. New from Pearson Custom Publishing!

Review of Matlab for Differential Equations. Lia Vas

AMATH 352 Lecture 3 MATLAB Tutorial Starting MATLAB Entering Variables

Algebra 2 Chapter 1 Vocabulary. identity - A statement that equates two equivalent expressions.

SCILAB - Kommandos und Keywords (Auswahl)

Final Exam Review: VBA

Precalculus REVERSE CORRELATION. Content Expectations for. Precalculus. Michigan CONTENT EXPECTATIONS FOR PRECALCULUS CHAPTER/LESSON TITLES

CD-ROM Appendix E: Matlab

FX 115 MS Training guide. FX 115 MS Calculator. Applicable activities. Quick Reference Guide (inside the calculator cover)

Parameters and Expressions

MATLAB Workshop 14 - Plotting Data in MATLAB

SCIENTIFIC CALCULATOR OPERATION GUIDE. <Write View>

Chapter 5 Functions. Introducing Functions

PTC Mathcad Prime 3.0 Keyboard Shortcuts

Getting Started with MasteringPhysics

5: Magnitude 6: Convert to Polar 7: Convert to Rectangular

Financial Econometrics MFE MATLAB Introduction. Kevin Sheppard University of Oxford

AIMMS Function Reference - Arithmetic Functions

How long is the vector? >> length(x) >> d=size(x) % What are the entries in the matrix d?

Math 0980 Chapter Objectives. Chapter 1: Introduction to Algebra: The Integers.

The KmPlot Handbook. Klaus-Dieter Möller Philip Rodrigues David Saxton

Quick Tour of Mathcad and Examples

(!' ) "' # "*# "!(!' +,

SAT Subject Math Level 2 Facts & Formulas

Biggar High School Mathematics Department. National 5 Learning Intentions & Success Criteria: Assessing My Progress

Analysis of System Performance IN2072 Chapter M Matlab Tutorial

Beginning Matlab Exercises

Thnkwell s Homeschool Precalculus Course Lesson Plan: 36 weeks

NEW YORK STATE TEACHER CERTIFICATION EXAMINATIONS

UNIVERSITY OF NEWCASTLE UPON TYNE

Microsoft Excel 2010 Part 3: Advanced Excel

Content. Chapter 4 Functions Basic concepts on real functions 62. Credits 11

MBA Jump Start Program

Estimated Pre Calculus Pacing Timeline

Expression. Variable Equation Polynomial Monomial Add. Area. Volume Surface Space Length Width. Probability. Chance Random Likely Possibility Odds

Vocabulary Words and Definitions for Algebra

MATHEMATICAL INSTITUTE UNIVERSITY OF OXFORD. Exploring Mathematics with MuPAD

Math 1. Month Essential Questions Concepts/Skills/Standards Content Assessment Areas of Interaction

Below is a very brief tutorial on the basic capabilities of Excel. Refer to the Excel help files for more information.

ab = c a If the coefficients a,b and c are real then either α and β are real or α and β are complex conjugates

The OptQuest Engine Java and.net Developer's Guilde

Dear Accelerated Pre-Calculus Student:

Display Format To change the exponential display format, press the [MODE] key 3 times.

Formulas, Functions and Charts

What are the place values to the left of the decimal point and their associated powers of ten?

SCIENTIFIC CALCULATOR OPERATION GUIDE. <V/R Series>

DRAFT. Further mathematics. GCE AS and A level subject content

Math Course Descriptions & Student Learning Outcomes

How do you compare numbers? On a number line, larger numbers are to the right and smaller numbers are to the left.

WORKBOOK. MATH 30. PRE-CALCULUS MATHEMATICS.

Getting to know your TI-83

PRE-CALCULUS GRADE 12

Gerrit Stols

Summary of important mathematical operations and formulas (from first tutorial):

Florida Math Correlation of the ALEKS course Florida Math 0028 to the Florida Mathematics Competencies - Upper

Credit Number Lecture Lab / Shop Clinic / Co-op Hours. MAC 224 Advanced CNC Milling MAC 229 CNC Programming

CRLS Mathematics Department Algebra I Curriculum Map/Pacing Guide

MATLAB Programming. Problem 1: Sequential

Algebra I Vocabulary Cards

Math Placement Test Practice Problems

Week 13 Trigonometric Form of Complex Numbers

ERDAS Spatial Modeler Language Reference Manual

FX 260 Training guide. FX 260 Solar Scientific Calculator Overhead OH 260. Applicable activities

TI-Nspire CAS Graphing Calculator

Math Review. for the Quantitative Reasoning Measure of the GRE revised General Test

MATH 0110 Developmental Math Skills Review, 1 Credit, 3 hours lab

GRE Prep: Precalculus

Metas.UncLib. Michael Wollensack und Marko Zeier. Metas Seminar Ein Messunsicherheitsrechner für Fortgeschrittene

Part VI. Scientific Computing in Python

Quick Reference ebook

ModuMath Basic Math Basic Math Naming Whole Numbers Basic Math The Number Line Basic Math Addition of Whole Numbers, Part I

MATH 132: CALCULUS II SYLLABUS

Linear Algebra and TI 89

Maple Quick Start. Introduction. Talking to Maple. Using [ENTER] 3 (2.1)

Trigonometric Functions: The Unit Circle

The Center for Teaching, Learning, & Technology

Algebra. Exponents. Absolute Value. Simplify each of the following as much as possible. 2x y x + y y. xxx 3. x x x xx x. 1. Evaluate 5 and 123

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.

Differentiation and Integration

fx-83gt PLUS fx-85gt PLUS User s Guide

Trigonometry Review with the Unit Circle: All the trig. you ll ever need to know in Calculus

Transcription:

MATLAB Commands and Functions Dr. Brian Vick Mechanical Engineering Department Virginia Tech General Purpose Commands Operators and Special Characters / 3 Commands for Managing a Session / 3 Special Variables and Constants / 4 System and File Commands / 4 Input/Output and Formatting Commands Input/Output Commands / 5 Format Codes for fprintf and fscanf / 5 Numeric Display Formats / 5 Vector, Matrix and Array Commands Array Commands / 6 Special Matrices / 6 Matrix Arithmetic / 6 Matrix Commands for Solving Linear Equations / 6 Cell Array Functions / 7 Structure Functions / 7 Plotting Commands Basic xy Plotting Commands / 8 Plot Enhancement Commands / 8 Specialized Plot Commands / 8 Colors, Symbols and Line Types / 9 Three-Dimensional Plotting Commands / 9 Histogram Functions / 9 MATLAB Commands 1

Programming Logical and Relational Operators / 10 Program Flow Control / 10 Logical Functions / 10 M-Files / 11 Timing /11 Mathematical Functions Exponential and Logarithmic Functions / 12 Trigonometric Functions / 12 Hyperbolic Functions / 12 Complex Functions / 13 Statistical Functions / 13 Random Number Functions / 13 Numeric Functions / 13 String Functions / 13 Numerical Methods Polynomial and Regression Functions / 14 Interpolation Functions / 14 Numerical Integration Functions / 14 Numerical Differentiation Functions / 14 ODE Solvers / 15 Predefined Input Functions / 15 Symbolic Math Toolbox Functions for Creating and Evaluating Symbolic Expressions / 16 Functions for Manipulating Symbolic Expressions / 16 Symbolic Calculus Functions / 16 Symbolic Solution of Algebraic and Transcendental Equations / 17 Symbolic Solution of Differential Equations / 17 Laplace Transform Functions / 17 Symbolic Linear Algebra Functions / 17 MATLAB Commands 2

General Purpose Commands Operators and Special Characters + Plus; addition operator. - Minus; subtraction operator. * Scalar and matrix multiplication operator..* Array multiplication operator. ^ Scalar and matrix exponentiation operator..^ Array exponentiation operator. \ Left-division operator. / Right-division operator..\ Array left-division operator../ Array right-division operator. : Colon; generates regularly spaced elements and represents an entire row or column. ( ) Parentheses; encloses function arguments and array indices; overrides precedence. [ ] Brackets; enclosures array elements.. Decimal point. Ellipsis; line-continuation operator., Comma; separates statements and elements in a row. ; Semicolon; separates columns and suppresses display. % Percent sign; designates a comment and specifies formatting. _ Quote sign and transpose operator.._ Nonconjugated transpose operator. = Assignment (replacement) operator. Commands for Managing a Session clc clear exist global help lookfor quit who whos Clears Command window. Removes variables from memory. Checks for existence of file or variable. Declares variables to be global. Searches for a help topic. Searches help entries for a keyword. Stops MATLAB. Lists current variables. Lists current variables (long display). MATLAB Commands 3

Special Variables and Constants ans Most recent answer. eps Accuracy of floating-point precision. i,j The imaginary unit -1. Inf Infinity. NaN Undefined numerical result (not a number). pi The number p. System and File Commands cd date delete diary dir load path pwd save type what wklread Changes current directory. Displays current date. Deletes a file. Switches on/off diary file recording. Lists all files in current directory. Loads workspace variables from a file. Displays search path. Displays current directory. Saves workspace variables in a file. Displays contents of a file. Lists all MATLAB files in the current directory. Reads.wk1 spreadsheet file. MATLAB Commands 4

Input/Output and Formatting Commands Input/Output Commands disp Displays contents of an array or string. fscanf Read formatted data from a file. format Controls screen-display format. fprintf Performs formatted writes to screen or file. input Displays prompts and waits for input. ; Suppresses screen printing. Format Codes for fprintf and fscanf %s Format as a string. %d Format as an integer. %f Format as a floating point value. %e Format as a floating point value in scientific notation. %g Format in the most compact form: %f or %e. \n Insert a new line in the output string. \t Insert a tab in the output string. Numeric Display Formats format short format long format short e format long e format bank format + format rat format compact format loose Four decimal digits (default). 16 decimal digits. Five digits plus exponent. 16 digits plus exponents. Two decimal digits. Positive, negative, or zero. Rational approximation. Suppresses some line feeds. Resets to less compact display mode. MATLAB Commands 5

Vector, Matrix and Array Commands Array Commands cat find length linspace logspace max min prod reshape size sort sum Concatenates arrays. Finds indices of nonzero elements. Computers number of elements. Creates regularly spaced vector. Creates logarithmically spaced vector. Returns largest element. Returns smallest element. Product of each column. Change size Computes array size. Sorts each column. Sums each column. Special Matrices eye ones zeros Creates an identity matrix. Creates an array of ones. Creates an array of zeros. Matrix Arithmetic cross dot Computes cross products. Computes dot products. Matrix Commands for Solving Linear Equations det inv pinv rank rref Computes determinant of an array. Computes inverse of a matrix. Computes pseudoinverse of a matrix. Computes rank of a matrix. Computes reduced row echelon form. MATLAB Commands 6

Cell Array Functions cell celldisp cellplot num2cell deal iscell Creates cell array. Displays cell array. Displays graphical representation of cell array. Converts numeric array to cell array. Matches input and output lists. Identifies cell array. Structure Functions fieldnames getfield isfield isstruct rmfield setfield struct Returns field names in a structure array. Returns field contents of a structure array. Identifies a structure array field. Identifies a structure array. Removes a field from a structure array. Sets contents of field. Creates structure array. MATLAB Commands 7

Plotting Commands Basic xy Plotting Commands axis fplot grid plot print title xlabel ylabel Sets axis limits. Intelligent plotting of functions. Displays gridlines. Generates xy plot. Prints plot or saves plot to a file Puts text at top of plot. Adds text label to x-axis. Adds text label to y-axis. Plot Enhancement Commands axes close close all figure gtext hold legend refresh set subplot text Creates axes objects. Closes the current plot. Closes all plots. Opens a new figure window. Enables label placement by mouse. Freezes current plot. Legend placement by mouse. Redraws current figure window. Specifies properties of objects such as axes. Creates plots in subwindows. Places string in figure. Specialized Plot Commands bar loglog polar semilogx semilogy stairs stem Creates bar chart. Creates log-log plot. Creates polar plot. Creates semilog plot (logarithmic abscissa). Creates semilog plot (logarithmic ordinate). Creates stairs pot. Creates stem plot. MATLAB Commands 8

Colors, Symbols and Line Types Color Symbol Line y yellow. point - solid m magenta o circle : dotted c cyan x x-mark -. dash dotted r red + plus -- dashed g green * star b blue d diamond w white v triangle (down) k black ^ triangle (up) < triangle (left) > triangle (right) p pentagram h hexagram Three-Dimensional Plotting Commands contour mesh meshc meshz plot3 surf surfc meshgrid waterfall zlabel Creates contour plot. Creates three-dimensional mesh surface plot. Same as mesh with contour plot underneath. Same as mesh with vertical lines underneath. Creates three-dimensional plots from lines and points. Creates shaded three-dimensional mesh surface plot. Same as surf with contour plot underneath. Creates rectangular grid. Same as mesh with mesh lines in one direction. Adds text label to z-axis. Histogram Functions bar hist histc Creates a bar chart. Aggregates the data into equally spaced bins. Aggregates the data into unequally spaced bins. MATLAB Commands 9

Programming Logical and Relational Operators == Relational operator: equal to. ~= Relational operator: not equal to. < Relational operator: less than. <= Relational operator: less than or equal to. > Relational operator: greater than. >= Relational operator: greater than or equal to. & Logical operator: AND. Logical operator: OR. ~ Logical operator: NOT. xor Logical operator: EXCLUSIVE OR. Program Flow Control break case else elseif end error for if otherwise return switch warning while Terminates execution of a loop. Provides alternate execution paths within switch structure. Delineates alternate block of statements. Conditionally executes statements. Terminates for, while, and if statements. Display error messages. Repeats statements a specific number of times Executes statements conditionally. Default part of switch statement. Return to the invoking function. Directs program execution by comparing point with case expressions. Display a warning message. Repeats statements an indefinite number of times. Logical Functions any all find finite isnan isinf isempty isreal True if any elements are nonzero. True if all elements are nonzero. Finds indices of nonzero elements. True if elements are finite. True if elements are undefined. True if elements are infinite. True if matrix is empty. True if all elements are real. MATLAB Commands 10

M-Files eval feval function global nargin nargout script Interpret strings containing Matlab expressions. Function evaluation. Creates a user-defined function M-file. Define global variables. Number of function input arguments. Number of function output arguments. Script M-files Timing cputime clock tic, toc CPU time in seconds. Current date and time as date vector. Start, stop a stopwatch timer. MATLAB Commands 11

Mathematical Functions Exponential and Logarithmic Functions exp(x) Exponential; e x. log(x) Natural logarithm; ln(x). log10(x) Common (base 10) logarithm; log(x)= log 10 (x). sqrt(x) Square root; x. Trigonometric Functions acos(x) acot(x) acsc(x) asec(x) asin(x) atan(x) atan2(y,x) cos(x) cot(x) csc(x) sec(x) sin(x) tan(x) Inverse cosine; arcos x = cos 1 (x). Inverse cotangent; arccot x = cot 1 (x). Inverse cosecant; arcs x = csc 1 (x). Inverse secant; arcsec x = sec 1 (x). Inverse sine; arcsin x = sin 1 (x). Inverse tangent; arctan x = tan 1 (x). Four-quadrant inverse tangent. Cosine; cos(x). Cotangent; cot(x). Cosecant; csc(x). Secant; sec(x). Sine; sin(x). Tangent; tan(x). Hyperbolic Functions acosh(x) acoth(x) acsch(x) asech(x) asinh(x) atanh(x) cosh(x) coth(x) csch(x) sech(x) sinh(x) tanh(x) Inverse hyperbolic cosine; cosh 1 (x). Inverse hyperbolic cotangent; coth 1 (x). Inverse hyperbolic cosecant; csch 1 (x). Inverse hyperbolic secant; sech 1 (x). Inverse hyperbolic sine; sinh 1 (x). Inverse hyperbolic tangent; tanh 1 (x). Hyperbolic cosine; cosh(x). Hyperbolic cotangent; cosh(x)/sinh(x). Hyperbolic cosecant; 1/sinh(x). Hyperbolic secant; 1/cosh(x). Hyperbolic sine; sinh(x). Hyperbolic tangent; sinh(x)/cosh(x). MATLAB Commands 12

Complex Functions abs(x) Absolute value; x. angle(x) Angle of a complex number x. conj(x) Complex conjugate of x. imag(x) Imaginary part of a complex number x. real(x) Real part of a complex number x. Statistical Functions erf(x) mean median std Computes the error function erf (x). Calculates the average. Calculates the median. Calculates the standard deviation. Random Number Functions rand Generates uniformly distributed random numbers between 0 and 1. randn Generates normally distributed random numbers. Numeric Functions ceil fix floor round sign Rounds to the nearest integer toward. Rounds to the nearest integer toward zero. Rounds to the nearest integer toward -. Rounds towards the nearest integer. Signum function. String Functions findstr strcmp char Finds occurrences of a string. Compares strings. Creates character string array MATLAB Commands 13

Numerical Methods Polynomial and Regression Functions conv deconv eig poly polyfit polyval roots Computes product of two polynomials Computes ratio of polynomials. Computes the eigenvalues of a matrix. Computes polynomial from roots. Fits a polynomial to data. Evaluates polynomial and generates error estimates. Computes polynomial roots. Interpolation Functions interp1 interp2 spline unmkpp Linear and cubic-spline interpolations of a function of one variable. Linear interpolation of a function of two variables. Cubic-spline interpolation. Computes the coefficients of cubic-spine polynomials. Root Finding and Minimization fmin fmins fzero Finds minimum of single-variable function. Finds minimum of multivariable function. Finds zero of single-variable function. Numerical Integration Functions quad quadl trapz Numerical integration with adaptive Simpson s rule. Numerical integration with adaptive Lobatto quadrature. Numerical integration with the trapezoidal rule. Numerical Differentiation Functions diff(x) Computes the difference between adjacent elements in the vector x. polyder Differentiates a polynomial, a polynomial product, or a polynomial quotient. MATLAB Commands 14

ODE Solvers ode23 ode45 ode113 ode23s ode23t ode23b ode15s odeset Nonstiff, low-order solver. Nonstiff, medium-order solver. Nonstiff, variable-order solver. Stiff, low-order. Moderately stiff, trapezoidal rule solver. Stiff, low-order solver. Stiff, variable-order solver. Creates integrator options structure for ODE solvers. Predefined Input Functions gensig sawtooth square stepfun Generates a periodic sine, square, or pulse input. Generates a periodic sawtooth input. Generates a square wave input. Generates a step function input. MATLAB Commands 15

Symbolic Math Toolbox Functions for Creating and Evaluating Symbolic Expressions class digits double ezplot findsym numden sym syms vpa Returns the class of an expression. Sets the number of decimal digits used to do variable precision arithmetic. Converts an expression to numeric form. Generates a plot of a symbolic expression. Finds the symbolic variables in a symbolic expression. Returns the numerator and denominator of an expression. Creates a symbolic variable. Creates one or more symbolic variables. Sets the number of digits used to evaluate expressions. Functions for Manipulating Symbolic Expressions collect expand factor poly2sym pretty simple simplify subs sym2poly Collects coefficients of like powers in an expression. Expands an expression by carrying out jpowers. Factors an expression. Converts a polynomial coefficient vector to a symbolic polynomial. Displays an expression in a form that resembles typeset mathematics. Searches for the shortest form of an expression. Simplifies an expression using Maple s simplification rules. Substitutes variables or expressions. Converts an expression to a polynomial coefficient vector. Symbolic Calculus Functions diff Dirac Heaviside int limit symsum taylor Returns the derivative of an expression. Dirac delta function (unit impulse). Heaviside function (unit step). Returns the integral of an expression. Returns the limit of an expression. Returns the symbolic summation of an expression. Returns the Taylor series of a function. MATLAB Commands 16

Symbolic Solution of Algebraic and Transcendental Equations solve Solves symbolic equations. Symbolic Solution of Differential Equations dsolve Returns a symbolic solution of a differential equation or set of equations. Laplace Transform Functions ilaplace laplace Returns the inverse Laplace transform. Returns the Laplace transform. Symbolic Linear Algebra Functions det eig inv poly Returns the determinant of a matrix. Returns the eigenvalues (characteristic roots) of a matrix. Returns the inverse of a matrix. Returns the characteristic polynomial of a matrix. MATLAB Commands 17