Week+of+4-15+to+4-21

Time to finish up Chapter 13. Section 13.5 addresses the use of imported images. He talks a lot about the specific memory features of images and how they are stored and things of that nature, and although it is interesting to read I don't think it's necessary to mark down. The essential main point of all of it is that an image in MATLAB is represented as a matrix of all of the pixels and each location in the matrix contains the RGB color of that pixel. Images can be displayed on the axis simply with the 'image' command. 'axis image' will set the axes to be proportional to the image. Each image is stored as an X*Y*3 array, with values of 0, 1, and 2 for the last coordinate indicating which color (Red, Green, or Blue). Each spot in the array, then, contains a number from 0 to 255 that represents the intensity of that color at that point on the x-y plane. If the top left pixel of an image were black, probing the image array for [1,1,0], [1,1,1], and [1,1,2] would return (0,0,0). Another quirk of image files in MATLAB is that when they are graphed, (0,0) for the axes is in the top-left, rather than bottom-left corner. The y-values, then, become more positive as they go downward instead of upward. There is actually a 'flipud' command that can be used to reorganize the y-values and color-values such that the image will be displayed as we are intuitively expecting. Multiple images can be plotted on the same axes using a more extensive version of 'image' with more parameters including a 'Parent' that allows the two or more images to share a space as long as they all call upon it. Another quirk of image files is that they are rectangular. I have encountered this time and time again in programming and usually a '.png' file with blank space rather than white is my go-to. The book uses a method to deal with this I had never seen or thought of before - it creates a mask for the extra space. I will not get into this because I frankly don't see a place where I'll be using this before the end of this year, but regardless this section is likely good for me to know. One final piece about images is that they can be mapped onto surfaces by adding a few parameters to 'surf'. Thus rather than the color gradient that 'surf' defaults to, one can make a surface with an image slapped onto it. The last section of chapter 13 is about treating several objects as one composite object, and rotating the entire composite object at once. 'hgtransform' creates a parent object that can have any number of child objects. It takes on a handle, and so once it is created, each of the child objects can have its Parent value set to the handle of the hgtransform object. The hgtransform can be changed geometrically by changing the 4*4 Matrix property of it, which can scale and rotate and translate the composite object. To make multiple transformations at once, one must simply make each separate transformation's matrix and then multiply them together when applying the transformation. For example, one could make the matrix R for rotating the image 90 degrees and T for translating it by 10 units, and then have 'T*R' set as the Matrix value for the composite image. Note, they are performed in sequence from right to left. The final note made in the chapter is that some of the higher level commands taught in this chapter can take the handle of an axes object as the first argument, but lower level functions need to set the axes object as their parent. Next I will begin Chapter 14. This chapter is about more mathematical capabilities of MATLAB and how to go about doing complex calculations with MATLAB's resources. Section 14.1 concerns derivatives. Unfortunately, MATLAB does not have a command to just take the derivative of a function on the spot. But, one can do so manually by creating an array that, for a given (x,y) pair, calculates the instantaneous rate of change by using an extremely small x increment for the function. In fact, in anticipation of people needing to do this, MATLAB contains a way to call upon the number, 'esp', which is the smallest number MATLAB can possibly handle, to be used for the x increment. If one tabulates a function in x and y arrays and keeps the values uniformly spaced, the 'gradient' command can be used to numerically find a rough version of the derivative at those points, and can be iterated to find higher order derivatives. Section 14.2 concerns integration in MATLAB. The first method proposed at the beginning of a section deals with tabulated functions. If x and f(x) are tabulated in such a way that x is uniformly spaced and each f corresponds with the correct x, then it can be integrated by adding rectangles formed by the constant change in x and each f value. This method is illustrated in the image below. This can simply be calculated by multiplying the sum of the f(x) array by the uniform change in x (for example in this picture that would be 0.5). The greater the number of points and the smaller the change in x, the more accurate this method will be. The rectangular method is a very rough approximation, though, and there is yet a better way to go about finding an integral - the trapezoidal method. Below is a picture that shows how much more closely a group of trapezoids will hug the curve than a group of rectangles. Since trapezoidal area is determined by ((b1+b2)/2)*h, aka the average value of the bases times the height, the trapezoids in the above picture could be found by calculating the sum of the averages of all pairs of y values that make trapezoids and multiplying them by the uniform change in x. In fact, this method is so key that MATLAB actually did provide a function for it - 'trapz'. 'trapz(y)' will find the averages of all the trapezoidal base pairs in a given array of y values, and all one must do is multiply it by the proper change in x. Also, one can just use both arrays as inputs if an x array is available. The next concept it addresses is the idea of integrating something stored in a MATLAB function. If this is the case, things are very easy. One must simply enter 'quadl(, a, b, tolerance)' and will get back the definite integral from a to b of that function to a maximum error of whatever tolerance was put down. The author then moves into a discussion of how to handle when there is an undefined constant in an equation being integrated, or something else where there are more variables. In this case, one must add those extra variables as parameters of the function, and set them before calling the function.