chapter5 - Chapter 5 Points In The Plane 5.1 Centroids...

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

View Full Document Right Arrow Icon
Chapter 5 Points In The Plane § 5.1 Centroids One-dimensional 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
Image of page 1

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

View Full Document Right Arrow Icon
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 0.2 0.4 0.6 0.8 1 0 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 user-specified 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. The ten points are displayed as dots (.) using Matlab ’s plot function while the centroid is displayed as an asterisk ( * ), again using the plot function. Notice the series of commands near the top of the script that set up the figure window. We wrote a comment for each command as a brief explanation to you—you don’t need to write such detailed comments in general.
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Sign up to access 24/7 study resources for your classes

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern