This preview shows pages 1–3. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: Chapter 5 Points In The Plane § 5.1 Centroids Onedimensional arrays—vectors, initializing vectors, colon expression for sub vectors, empty array , functions with vector parameters, functions that return vectors. § 5.2 Max’s and Min’s Algorithm for finding the max in a list, function plot and related graphics controls, function sprintf All of the programs that we have considered so far involve relatively few variables. The variables that we have used are scalar variables where only one value is stored in the variable at any time. We have seen problems that involve a lot of data, but there was never any need to store it “all at once.” This will now change. Tools will be developed that enable us to store a large amount of data that can be accessed during program execution. We introduce this new framework by considering various problems that involve sets of points in the plane. If these points are given by ( x 1 , y 1 ) , . . . , ( x n , y n ), then we may ask: • What is their centroid? • What two points are furthest apart? • What point is closest to the origin (0,0)? • What is the smallest rectangle that contains all the points? The usual input / fprintf methods for input and output are not convenient for problems like this. The amount of data is too large and too geometric. In this chapter we will be making extensive use of Matlab ’s graphics functions such as plot for drawing an x y plot, and ginput for reading in the x and y coordinates of a mouse click in a figure window on the screen. We postpone the detailed discussion about plot until the end of the chapter so that we can focus on another important concept in the early examples. For now, do not be concerned about the commands used to “set up the figure window” in the examples. Brief explanations are given in the program comments to indicate their effect. Be patient! Function plot will be explained in § 5.2. 259 260 Chapter 5. Points In The Plane 5.1 Centroids Suppose we are given n points in the plane ( x 1 , y 1 ) , . . . , ( x n , y n ). Collectively, they define a finite point set . Their centroid (¯ x, ¯ y ) is defined by ¯ x = 1 n n X i =1 x i ¯ y = 1 n n X i =1 y i . See Figure 5.1 . Notice that ¯ x and ¯ y are the averages of the x and y coordinates. The program 0.2 0.4 0.6 0.8 1 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 Click 10 points and the centroid will be displayed Figure 5.1 Ten Points and Their Centroid Example5 1 calculates the centroid of ten userspecified points to produce Figure 5.1 . The xy values that define ten points are obtained by clicking the mouse. The statement [xk,yk]= ginput(1) stores the x value of a mouse click in variable xk and the the y value in yk . The summations that are required for the centroid computation are assembled as the data is acquired....
View
Full
Document
This note was uploaded on 09/23/2007 for the course COM S 100 taught by Professor Fan/chew during the Spring '07 term at Cornell.
 Spring '07
 FAN/CHEW
 Row vector, Vector Motors, Line segment, red line

Click to edit the document details