Week+of+12-17+to+12-23

December 18th
Today I arrived at QuarkNet at 3:45. Chapter 4 - Matrices - is my next move with the textbook. Section 4.1 was very basic stuff I've already gone through about entering and indexing matrices, as well as using an apostrophe to transpose a matrix. The one thing I realized I may have left off in my previous logbook entries was the added use of the colon. Not only can it be stuck between two numbers in an index to indicate that all numbers between them (inclusive) should be indexed, a colon on its own as either the row or column of an index of a matrix indexes all of either the rows or the columns. Section 4.2 goes in depth about operations on matrices. Most of this was familiar, but it brought up for the first time identity matrices, inverses, and determinants. So, I toyed around with them in MATLAB a bit. I learned a few new commands from this process, and also refreshed my memory on matrices. The first thing my code shows is MATLAB's ability to sniff out bad matrices when you tell it to take an inverse. I used the 'det' function to show that the determinant (for 2x2 matrix found by subtracting the products of the diagonals, but for 3x3 or larger found by alternating adding and subtracting determinants of 2x2 matrices found within the matrix by a process I will not explain here). Since no inverse exists for a matrix whose determinant is 0, I decided to test MATLAB and attempt to take the inverse (using 'inv') of this matrix. MATLAB successfully blocked my attempt as shown by the error message (singular means the determinant is 0). The, I created a matrix whose inverse actually could be calculated, had MATLAB do so, and then checked my answer by making sure multiplying the matrix and its supposed inverse in fact did turn out to equal the identity matrix. In fact it did, and I solidified this by using the 'eye' command to generate the proper identity matrix, which matched my answer. Section 4.3 introduces the backslash operator. It is used to solve situations where multiplying the inverse of one matrix by another matrix would produce the desired answer. It bypasses the step of taking the inverse for the programmer and simplifies things. Below is an example. This screenshot shows that the backslash command creates the same result as going through the whole step of multiplying by the inverse. The book went into an extremely in-depth example of using matrices and the backslash operator to solve a system of five variables in a circuit. Section 4.4 addresses ones, zeros, and rand, which are the exact same functions discussed in last week's post about vectors (but with matrices, rather than always entering 1 in for the first input - number of rows - we not enter some other integer in correspondence with the desired matrix). In the conclusion of Chapter 4, the author explains how matrices and vectors are really types of arrays, which made me feel a little better about being stubborn in using the word "array" rather than other terms earlier. I had some spare time, so I moved on to the beginning of Chapter 5 - control flow commands. Control flow commands are the commands that govern loops. I already discussed these in my 'PiggyBank' script, but the book is likely to provide a couple new factoids as usual. Section 5.1 explains the 'if' statement. This section progressed through 'if', 'else', and 'elseif' and did not really provide anything new. The one thing I have to remember with MATLAB 'if' statements is that the 'end' statement is used rather than brackets, contrary to Java. Otherwise, nothing is new after my experience with Java. Section 5.2 listed and briefly discussed the various logical operators for testing variables. There were two differences I noticed from Java. The first was that in Java, '!' meant "not", but in MATLAB, '~' means "not". Also, MATLAB provides a way to test element-by-element in arrays for "and" and "or" operators - rather than '&&' and '||', one simply uses '&' and '|'. Today I left QuarkNet at 5:45.

December 19th
Today I arrived at QuarkNet at the quite late hour of 5:00, but it was my only chance until January to stop in, so I figured I might as well. I picked up where I left off, commencing section 5.3. Section 5.3 is about logical variables, or as I am used to calling them, boolean variables. These variables are either true or false, and sometimes that is interpreted as 1 (true) or 0 (false), as I mentioned previously in the logbook. Nothing really groundbreaking was mentioned by the book in this section. Section 5.4 explains 'for' loops. I have done a lot of work with these in programs I've written and other than the minor differences I mentioned earlier in the logbook, such as the difference in the way conditions are stated - for example, the Java equivalent of what would be j=0:1:10 in MATLAB is (j=0;j<=10;j++). The sequencing in MATLAB is slightly more crisp. The one advantage Java has over MATLAB in relation to 'for' loops is the ability to iterate through an array populated with any kind of object. This is a way to bypass some writing if you were to set up a variable and calculate the length of the array and index each element, and it also avoids an issue of casting (translating between class types). This specialized 'for' loop allows you to tell the program to check out each element of an array full of whatever one by one. As far as I can tell MATLAB has no equivalent, but maybe I'm wrong. Section 5.5 is about 'while' loops. I covered most of what was mentioned previously in the logbook. One thing I realized I didn't mention when comparing 'for' loops and 'while' loops is that 'while' loops have the capability to handle strings, boolean variables, or whatever as a condition, whereas 'for' loops require a numerical index and increment. So, a while loop could be executed continually while a variable was false until something happened in one of the iterations that turned the variable to true. Section 5.6 addresses the other "control flow commands" that can be helpful aside from 'if', 'for', and 'while'. These would be 'switch' and 'break', namely. 'switch' is a way to process multiple options that is slightly different from the 'if/else' construct. The book provided an entertaining example to illustrate the functionality of 'switch', so I copied it and showed it below. The use of 'switch', 'case', and 'otherwise' is a good way to process a group of possibilities, as shown above, and slightly more comfortable and logical than a group of if/else statements. 'break' statements are used to cut off things, especially 'for' loops, before they are finished. The author of the textbook recommends against those and I agree with him. In my experience, it is just plain better to rethink the way you set things up than to use a 'break' statement. It is more difficult to debug, and most 'for' loops that seem to need a 'break' could be converted into a 'while' loop free of 'break's. That concluded Chapter 5. I decided my next move should be Chapter 8 because it is shorter than 6 and 7 so I figured I could finish it today and leave for break without something hanging. Chapter 8 is about different data types and ways to handle many data types in one program. Section 8.1 is about cell arrays. Cell arrays are a way to put multiple data of different types under one roof. Below is an example of a cell array. I chose to also show it in the spreadsheet view because this is an especially useful tool when handling cell arrays, since it shows what the command window will simplify (in this case, the array inside ca{2,1}). The use of braces instead of brackets or parenthesis is what designates a variable as a cell array. Section 8.2 is about structures. Structures are a way to collect multiple data of varying types that can be called upon by strings rather than the number indexes common to arrays. Additionally, structures can be subdivided into arrays. Below is an example using documentation of a CD collection. Structures use a period to index a certain variable and parenthesis before the period to reference certain parts if the structure is separated into an array. In this example, I was able to seamlessly categorize different CDs and attribute both strings and integers to the same entry. Section 8.3 addresses MATLAB's ability to handle complex numbers. Complex numbers can be entered and indexed in a variety of ways, as shown below. Most of this is pretty self explanatory. The 'complex' command asks for an input of the real part and then the coefficient of the imaginary part. When entering complex numbers flat out, one can use i or j, although it is always stored as i. I am a little rusty on my math for the polar stuff, but the exponential/polar form of entering is useful. Also, the ability of MATLAB to process negative square roots is important. The commands 'real' and 'imag' obviously just return the real part or imaginary part. 'abs' and 'angle' give the polar components, which once again I am a little rusty on. 'conj' gives the complex conjugate of a given complex number. Section 8.4 discusses function handles. The handle for a specific function is notated just like a Twitter handle, entertainingly enough. One must simply put an @ before the name of a function to designate the handle. The reason function handles are useful is because they allow you to build code in MATLAB where one function uses another function as an input. Section 8.5 briefly mentions a few other data classes in MATLAB. One is the 'sparse' class, which is a type of matrix in which few elements are nonzero, which apparently can be used to simplify operations when suitable. The author beats around the bush of multidimensional arrays (apparently I was wrong way back in the beginning when I thought there was no MATLAB equivalent of adding dimensions to an array, which doesn't surprise me) but doesn't really explain anything about them. The one other thing he mentions is storing numbers in a different form than decimal. 'int8', 'int16', 'uint16', etc. Storing in one of the classes beginning with 'u' indicates that the sign of the number is irrelevant. That is all for Chapter 8 and my day, week, month, and year. I am leaving QuarkNet at 7:00. I'll be back in January 2013 (given the world doesn't end on Friday). Merry Christmas and Happy New Year!