Unformatted text preview:

PowerPoint PresentationSlide 2Slide 3Slide 4Slide 5Slide 6Slide 7Slide 8Slide 9Slide 10Slide 11Slide 12Slide 13Slide 141MATLAB Lecture #1 EGR 110 – Engineering GraphicsReading Assignment: MATLAB handout MATLAB Assignment: MATLAB Assignment #1MATLABMATLAB is an extremely powerful software application and development tool that is widely used in most universities in technical fields. Similar programs include MathCAD and Mathematica. In this course some basic features of MATLAB will be covered. It is very likely that engineering students will see MATLAB used in many later undergraduate and graduate engineering courses.In the past engineers commonly wrote programs to perform various types of engineering calculations. Many of those calculations can now be easily performed with functions and features that are built into MATLAB, including:• mathematical, statistical, and logical functions• graphing functions• curve-fitting• equation solving• symbolic calculations• advanced functions with applications in later engineering coursesSo why is it called MATLAB? MATLAB is short for MATrix LABoratory. MATLAB was originally designed for manipulating matrices. In fact, when you use a simple variable such as x in MATLAB, it is actually stored as a (1x1) matrix. In order to understand how MATLAB works, we will need to be familiar with matrix calculations. We will cover more on this topic later.2MATLAB EnvironmentWhen MATLAB is launched, several windows will appear. An important part of learning MATLAB is learning how to use each of these windows.Command WindowCurrent Folder WindowCommand History WindowAs we will see later, MATLAB uses a number of other windows as well, including:• Editor – for creating and editing MATLAB programs• Array editor• Help window• Properties windowsMATLAB Lecture #1 EGR 110 – Engineering GraphicsWorkspace Window3Vectors and scalars in MATLABMATLAB is designed to work with vector quantities places in matrices, where the elements of the matrix are placed inside brackets [ ] with the elements in each row separated by spaces and the rows separated by semicolons. However, MATLAB can also be used to work with variables defined by a single value called scalars.Example:Type of quantity Mathematical notation: MATLAB notation:Vector A = [2 3 4;7 9 –1]Scalar x = 2 x = 2197432 A Variable names in MATLAB• are case-sensitive• can contain up to 63 characters (any characters beyond the 63rd are ignored)• must start with a letter, followed by any comb. of letters, numbers, and underscores• cannot contain spacesExamples: (List several in class)MATLAB Lecture #1 EGR 110 – Engineering Graphics4Expressions in MATLABMATLAB, like most programming languages, requires that expressions contain a single variable to the left of the assignment operator (equals sign).Example: X = 2*A + 3*B - 15SinglevariableAssignmentoperatorExpression involving variables, functions, numbers, etcAdditionally, MATLAB performs the calculations to the right of the assignment operator (=) using existing values of variables and then assigns the result to the variable to the left of the equals sign.So the expression X = X + 2 should be interpreted as Xnew = Xold + 2Note the result of the following sequence of instructions in MATLAB (try it!):Note: a semicolon (;) after a command suppresses the value from being printedMATLAB Lecture #1 EGR 110 – Engineering Graphics5MATLAB’s Basic Scalar Arithmetic Operators Operation SymbolExampleAddition +X = A + BSubtraction - X = A - BMultiplication * X = A*BDivision / X = A/BExponentiation ^ X = A^2 + B^2 Operation SymbolPrecedenceParentheses ( )HighestExponentiation ^ Negation - Multiplication or division * or / Addition or subtraction + or - LowestMATLAB’s Order of Operations (for scalars)Operators are executed left to right using the following precedence.Examples: (List several in class)MATLAB Lecture #1 EGR 110 – Engineering Graphics6 Examples: (Order of operations) – Try these by hand and then verify in MATLAB.MATLAB Lecture #1 EGR 110 – Engineering Graphics______) :(Answer A^2-A*6A______) :(Answer 1AA______) :(Answer )2/1()^(F8______) :(Answer 2/1)^(F7______) :(Answer D*DB^F6______) :(Answer B/A/CF5______) :(Answer C)*B/(A F4______) :(Answer C*B/AF3______) :(Answer D*CB*AF2______) :(Answer CDABF12;D3;C4;B5;ABABA7 Examples: (Order of operations) – Write MATLAB expressions for F1 – F5, then test them in MATLAB using A = 5, B = 4, C = 3, and D = 2.MATLAB Lecture #1 EGR 110 – Engineering GraphicsB1A11 F5AF4B-A F3DC1BA F2DCBA F13/43328Function Descriptionpi returns  to 15 significant digitscos(x) returns cosine of x, with x in radianssin(x) returns sine of x, with x in radianstan(x) returns tangent of x, with x in radiansacos(x) returns arccosine of x, in radiansasin(x) returns arcsine of x, in radiansatan(x) returns arctangent of x, in radiansexp(x) returns the value of exsqrt(x) returns the square root of xfactorial(x) returns factorial of xlog(x) returns ln(x)log10(x) returns log10(x)abs(x) returns absolute value of xsinh(x) returns the hyperbolic sine of xround(x) rounds x off toward nearest integerceil(x) rounds x toward positive infinityfloor(x) rounds x toward negative infinityMATLAB built-in functionsMATLAB has hundreds of built-in functions. A few of the functions commonly used with scalars are shown in the table.MATLAB Lecture #1 EGR 110 – Engineering GraphicsMore functionsOpen MATLAB and select Help – Function Browser and check out the vast number of functions available in MATLAB. What do the following functions do?sind(A)hypot (a,b)cot(A)mod(N)9 Examples: (Functions) Write MATLAB expressions for each of the following functions. Check the results using MATLAB.MATLAB Lecture #1 EGR 110 – Engineering Graphics  21-1-42-212sin Hdegrees)in result the(express 5.0cos radians)in result the(express 4sin ln(25) Dnotation) scientific (use 10 x 1.2 Jm) m)(20 (10Area10e V(t)radians 3cos*100 F)cos(60*100 FR! Result R Circle Of Area10 Examples: (Functions) Write MATLAB expressions for each of the following functions. Check the results using MATLAB.MATLAB Lecture #1 EGR 110 – Engineering


View Full Document

TCC EGR 110 - EGR 110 Lecture notes

Download EGR 110 Lecture notes
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view EGR 110 Lecture notes and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view EGR 110 Lecture notes 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?