Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

MATLAB Arrays - Computational Methods - Lecture Slides, Slides of Calculus for Engineers

These are the Lecture Slides of Computational Methods which includes Thévenin’s Equivalent Circuit, Circuit Simplification, Analysis of Power Transfer, Voltage Division, Analytical Game Plan, Array Operation, Element Operations, Number of Allowable Values etc.Key important points are: Matlab Arrays, Row and Column Vectors, Arrays and Matrices, Arithmetic Operations, Analyze Polynomial Functions, Unit-Vectors, Appending Vectors, Regularly Spaced Elements, Number of Values, Linspace Comand

Typology: Slides

2012/2013

Uploaded on 03/26/2013

abduu
abduu 🇮🇳

4.4

(47)

200 documents

1 / 52

Toggle sidebar

Related documents


Partial preview of the text

Download MATLAB Arrays - Computational Methods - Lecture Slides and more Slides Calculus for Engineers in PDF only on Docsity! Engr/Math/Physics 25 Chp2 MATLAB Arrays: Part-1 Docsity.com Learning Goals • Learn to Construct 1-Dimensional Row and Column Vectors • Create MULTI-Dimensional ARRAYS and MATRICES • Perform Arithmetic Operations on Vectors and Arrays/Matrices • Analyze Polynomial Functions Docsity.com “Appending” Vectors • Can create a NEW vector by ''appending'' one vector to another • e.g.; to create the row vector u whose first three columns contain the values of r = [2,4,20] and whose 4th, 5th, & 6th columns contain the values of w = [9,-6,3] – Typing u = [r,w] yields vector u = [2,4,20,9,-6,3] >> r = [2,4,20]; w = [9,-6,3]; >> u = [r,w] u = 2 4 20 9 -6 3 Docsity.com Colon (:) Operator • The colon operator (:) easily generates a large vector of regularly spaced elements. • Typing >>x = [m:q:n] – creates a vector x of values with a spacing q. The first value is m. The last value is n IF m - n is an integer multiple of q. IF NOT, the last value is LESS than n. >> p = [0:2:8] p = 0 2 4 6 8 >> r = [0:2:7] r = 0 2 4 6 Docsity.com Colon (:) Operator cont. • To create a row vector z consisting of the values from 5 to 8 in steps of 0.1, type z = [5:0.1:8]. • If the increment q is OMITTED, it is taken as the DEFAULT Value of +1. >> s =[-11:-6] s = -11 -10 -9 -8 -7 -6 >> t = [-11:1:-6] t = -11 -10 -9 -8 -7 -6 Docsity.com logspace Example • Consider this command >> y =logspace(-1,2,6) y = 0.1000 0.3981 1.5849 6.3096 25.1189 100.0000  Calculate the Power of 10 increment ( ) ( )1−−=∆ nabp  In this case ( )( ) ( ) 6.053 1612 == −−−=∆p ( )( )110 −∆+= kpaky  In this Case k Power yk 1 -1 0.1000 2 -0.4 0.3981 3 0.2 1.5849 4 0.8 6.3096 5 1.4 25.1189 6 2 100.0000  for k = 1→6, then the kth y-value Docsity.com logspace Example (alternative) • Consider this command >> y =logspace(-1,2,6) y = 0.1000 0.3981 1.5849 6.3096 25.1189 100.0000  Take base-10 log of the above  Calc Spacing Between Adjacent Elements with diff command >> yLog10 = log10(y) yLog10 = -1.0000 -0.4000 0.2000 0.8000 1.4000 2.0000 >> yspc = diff(yLog10) yspc = 0.6000 0.6000 0.6000 0.6000 0.6000 ( ) ( ) [ ]( ) ( ) 5316121 =−−−=−−=∆ nabp Docsity.com Vector: Magnitude, Length, and Absolute Value • Keep in mind the precise meaning of these terms when using MATLAB – The length command gives the number of elements in the vector – The magnitude of a vector x having elements x1, x2, …, xn is a scalar, given by √(x12 + x22 + … + xn2), and is the same as the vector's geometric length – The absolute value of a vector x is, in MATLAB, a vector whose elements are the arithmetic absolute values of the elements of x Docsity.com 3D Vector Length Example - Run vAB = 2 1 -5 sqs = 4 1 25 sum_sqs = 30 LAB = 5.4772 % Bruce Mayer * ENGR36 % 25Aug09 * Lec03 % file = VectorLength_0908.m % % Find the length of a Vector AB with %% tail CoOrds = (0, 0, 0) %% tip CoOrds = (2, 1, -5) % % Do Pythagorus in steps vAB = [2 1 -5] % define vector sqs = vAB.*vAB % sq each CoOrd sum_sqs = sum(sqs) % Add all sqs LAB = sqrt(sum_sqs) % Take SQRT of the sum-of-sqs Docsity.com Matrices/Arrays • A MATRIX has multiple ROWS and COLUMNS. For example, the matrix M:             = 15123 948 7316 1042 M  VECTORS are SPECIAL CASES of matrices having ONE ROW or ONE COLUMN.  M contains • FOUR rows • THREE columns Docsity.com Making Matrices • For a small matrix you can type it row by row, separating the elements in a given row with spaces or commas and separating the rows with semicolons. For example, typing       = 7316 1042 A  spaces or commas separate elements in different columns, whereas semicolons separate elements in different rows.  The Command • >>A = [2,4,10;16,3,7];  Generates Matrix Docsity.com M ake M atrix Exam ple >> r1 = [1:5] r1 = 1 2 3 4 5 >> r2 = [6:10] r2 = 6 7 8 9 10 >> r3 = [11:15] r3 = 11 12 13 14 15 >> r4 = [16:20] r4 = 16 17 18 19 20 >> r5 = [21:25] r5 = 21 22 23 24 25 >> A = [r1;r2;r3;r4;r5] A = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 Docsity.com Array Addressing • The COLON operator SELECTS individual elements, rows, columns, or ''subarrays'' of arrays. Some examples: – v(:) represents all the row or column elements of the vector v – v(2:5) represents the 2nd thru 5th elements; that is v(2), v(3), v(4), v(5). – A(:,3) denotes all the row-elements in the third column of the matrix A. – A(:,2:5) denotes all the row-elements in the 2nd thru 5th columns of A. – A(2:3,1:3) denotes all elements in the 2nd & 3rd rows that are also in the 1st thru 3rd columns. Docsity.com Array Extraction • You can use array indices to extract a smaller array from another array. For example, if you first create the array B             = 1715123 25948 187316 131042 B  to Produce SubMatrix C type C = B(2:3,1:3) Rows 2&3 Cols 1-3       = 948 7316 C Docsity.com Matrix Commands cont Command Description max(A) * Returns the algebraically largest element in A if A is a VECTOR. * Returns a row vector containing the largest elements in each Column if A is a MATRIX. * If any of the elements are COMPLEX, max(A) returns the elements that have the largest magnitudes. [x,k] = max(A) Similar to max(A) but stores the maximum values in the row vector x and their indices in the row vector k. Docsity.com Matrix Commands cont Command Description min(A) and [x,k] = min(A) Like max but returns minimum values. sort(A) Sorts each column of the array A in ascending order and returns an array the same size as A. sum(A) Sums the elements in each column of the array A and returns a row vector containing the sums. Docsity.com Examples: Matrix Commands • Given Matrix A           −= 73 510 26 A >> A = [[6,2]; [-10,5]; [3,7]]; >> size(A) ans = 3 2 >> length(A) ans = 3 >> max(A) ans = 6 7 >> min(A) ans = -10 2 Docsity.com MultiDimensional (≥3) Arrays • 3D (or more-D) Arrays Consist of two-dimensional arrays that ar “layered” to produce a third dimension. – Each “layer” is called a page. 3D pg1 pg2 pg3 pg4 Command Description cat(n,A,B,C, ...) Creates a new array by concatenating the arrays A,B,C, and so on along the dimension n. Docsity.com Vectors Digression • VECTOR ≡ Parameter Possessing Magnitude And Direction, Which Add According To The Parallelogram Law – Examples: Displacements, Velocities, Accelerations • SCALAR ≡ Parameter Possessing Magnitude But Not Direction – Examples: Mass, Volume, Temperature • Vector Classifications – FIXED or BOUND Vectors Have Well Defined Points Of Application That CanNOT Be Changed Without Affecting An Analysis Docsity.com Vectors cont. – FREE Vectors May Be Moved In Space Without Changing Their Effect On An Analysis – SLIDING Vectors May Be Applied Anywhere Along Their Line Of Action Without Affecting the Analysis – EQUAL Vectors Have The Same Magnitude and Direction – NEGATIVE Vector Of a Given Vector Has The Same Magnitude but The Opposite Direction Equal Vectors Negative Vectors Docsity.com Vector Notation • In Print and Handwriting We Must Distinguish Between – VECTORS – SCALARS • These are Equivalent Vector Notations PPP ≡≡≡P • Boldface Preferred for Math Processors • Over Arrow/Bar Used for Handwriting • Underline Preferred for Word Processor Docsity.com Dot Product of 2 Vectors • The SCALAR PRODUCT or DOT PRODUCT Between Two Vectors P and Q Is Defined As ( )resultscalarcosθPQQP =•  PQQP  •=• ( ) 2121 QPQPQQP  •+•=+• ( ) undefined =•• SQP   Scalar-Product Math Properties • ARE Commutative • ARE Distributive • Are NOT Associative – Undefined as (P•S) is NO LONGER a Vector Docsity.com Scalar Product – Cartesian Comps • Scalar Products With Cartesian Components 000 111 =•=•=• =•=•=• ikkjji kkjjii   ( ) ( )kQjQiQkPjPiPQP zyxzyx  ++•++=• 2222 PPPPPP QPQPQPQP zyx zzyyxx =++=• ++=•    MATLAB Makes this Easy with the dot(p,q) Command >> p = [13,-17,-7]; q = [-16,5,23]; >> pq = dot(p,q) pq = -454 >> qp = dot(q,p) qp = -454 >> r = [1 3 5 7]; t = [8,6,4,2]; >> rt = dot(r,t) rt = 60 Docsity.com Vector Prod: Rectangular Comps • Vector Products Of Cartesian Unit Vectors 0 0 0 =×=×−=× −=×=×=× =×−=×=× kkikjjki ijkjjkji jikkijii    ( ) ( )kQjQiQkPjPiPQPV zyxzyx  ++×++=×= ( ) ( ) ( )kQPQPjQPQPiQPQP xyyxzxxzyzzy  −+−+−= zyx zyx QQQ PPP kji QP  =×  Vector Products In Terms Of Rectangular Coordinates • Summarize Using Determinate Notation Docsity.com cross command • 3D Vector (Cross) product Evaluation is Painful – c.f. last Slide • MATLAB makes it easy with the cross(p,q) command – The two Vectors MUST be 3 Dimensional >> p = [13,-17,-7]; >> q = [-16,5,23]; >> pxq = cross(p,q) pxq = -356 -187 -207 >> qxp = cross(q,p) qxp = 356 187 207 Docsity.com Array Addition and Subtraction • Add/Subtract Element-by-Element >> A = [6,-2;10,3]; >> B = [9,8;-12,14]; >> A+B ans = 15 6 -2 17 [ ] [ ] [ ]       − =      − +      − =+ −−=−−−−=− 172 615 1412 89 310 26 16528194113917 BA qp >> p = [17 -9 3]; >> q = [-11,-4,19]; >> p-q ans = 28 -5 -16  Using MATLAB Docsity.com CAVEAT • 2D arrays are described as ROWS x COLUMNS – Elemement of D(2,5) • 2 → ROW-2 • 5 → COL-5 • ROW Vector → COMMAS • COL Vector → SemiColons >> r = [4,73,17] r = 4 73 17 >> c = [13;37;99] c = 13 37 99 Docsity.com Caveat cont • Array operations often CONCATENATE or APPEND – This Can Occur unexpectedly – Use the clear command to start from scratch concatenate con·cat·e·nate ( P ) Pronunciation Key (kn-ktn-t, kn-) tr.v. con·cat·e·nat·ed, con·cat·e·nat·ing, con·cat·e·nates 1. To connect or link in a series or chain. 2. Computer Science. To arrange (strings of characters) into a chained list. adj. (-nt, -nt) 1. Connected or linked in a series. Docsity.com Rectangular Force Components • Using Rt-Angle Parallelogram Resolve F into Perpendicular Components yx FFF += yxyx FF jiFFF +=+=  Define Perpendicular UNIT Vectors Which Are Parallel To The Axes  Vectors May then Be Expressed As Products Of The Unit Vectors With The SCALAR MAGNITUDES Of The Vector Components Docsity.com 3D Rectangular Components • Resolve Fh into rectangular components  Resolve F into horizontal and vertical components. yh yy FF FF F θ θ sin cos = = = F φθ φ φθ φ sinsin sin cossin cos y hz y hx F FF F FF = = = =  The vector F is contained in the plane OBAC. Docsity.com 3D Rectangular Comp. cont. ( ) kjiλ λ kji kjiF zyx zyx zyx zzyyxx F F FFF FFFFFF θθθ θθθ θθθ coscoscos coscoscos coscoscos ++= = ++= ++= ===  With the angles between F and the axes  λ is a UNIT VECTOR along the line of action of F, and cosθx, cosθy, and cosθz, are the DIRECTION COSINES for F Docsity.com 2-Pt Direction Cosines • Consider Force, F, Directed Between Pts – M(x1,y1,z1) – N(x2,y2,z2) • The Vector MN Joins These Points with Scalar Components dx, dy, dz ( ) d d d d d d d FdF d Fd F d FdF ddd d F dddd z z y y x x z z y y x x zyx zyx === === ++== ++== θθθ coscoscos 1 222 kjiλF d 12 1212 zzd yydxxd dddMN z yx zyx −= −=−= ++== kjid Docsity.com
Docsity logo



Copyright © 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved