L3 - CGN 3421 - Computer Methods Gurley Lecture 3 -...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
CGN 3421 - Computer Methods Gurley Lecture 3 - Functions and Control Structures page 21 of 38 Lecture 3 - Functions and Control Structures Range variables vs. vectors: Continuing out discussion of using range vectors vs. using vectors. Recall our general rule will be to use range variables to create and reference vectors, and vectors will be used to store our information for manipulation (equations etc.) and graphing. Mail Box Analogy : Think of the process of storing data like putting stuff into a series of mailboxes. Not only do we need to keep track of what we put into the mailboxes, but we also need to keep track of where the mailboxes are. Range variables will be used to point at mailbox locations. Vectors will be used to rep- resent the contents of the mailboxes. If I want only the stuff stored in the 5 th mailbox, I will point to that mailbox to retrieve its contents. This is done using an index as in x 5 . IMPORTANT: An index to an array must be an integer. The index represents a discrete location in mem- ory. There is no 3.4 th mailbox on the block, and there is no 3.4 th spot in a vector. The contents of that discrete spot can be a non-integer, a word, etc., but its location (the index, the subscript) must be an inte- ger. Range Variables: Indexing an array (pointing to a spot) can be done one spot at a time (with a constant or scalar variable), or multiple spots at one time (with a range variable). A range variable can be used to point to multiple locations at one time. Use an index to reference specific locations within an array e.g. i := 4 Grade i OR JUST Grade 4 refers to 89.3 in the vector The index can be a number, a scalar variable, or a range variable. In any case the index must be an integer, as it is pointing to one or more discretely numbered locations (mailboxes) Example : Indexing specific spots within a list of grandes: Grade := [56 72 65 98 84 91]; I can use a range variable to refer to only the first 3 spots, or some interior spots: vector ’Grade’ contains 6 locations to store information content (vector ‘Grade’) Location of content (index one at a time or 12.3 6.2 5.3 89.3 93.94 26 1 2 3 4 5 6 use range variable i := 1 ; 6) index MUST be an integer i1 3 .. := Grade i 56 72 65 = i3 5 .. := Grade i 65 98 84 = 3 , 5 .. := Grade i 56 65 84 =
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CGN 3421 - Computer Methods Gurley Lecture 3 - Functions and Control Structures page 22 of 38 Example : Using a range variable to calculate the mean value of the same list of grades: Example : Using a range variable to calculate the mean value of portions of the list of grades: Example: Take the summation of a complete vector to find an average (different kinda summation) Example: Multiplying two different vectors together by default gives the scalar dot-product as a result. If we wish to multiply element by element, use the range variable idea. Here we only want the first 3 values of Inertia. So we use a range variable with values 1, 2 and 3.
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 05/18/2011 for the course CGN 3421 taught by Professor Long during the Spring '08 term at University of Florida.

Page1 / 18

L3 - CGN 3421 - Computer Methods Gurley Lecture 3 -...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online