Week+of+12-3+to+12-9

December 3rd
Today I arrived at QuarkNet at 4:00. I re-familiarized myself with my "PiggyBank" script. Now it's time to explain it. Here's another copy of the screenshots: This is eerily reminiscent of calculator programming, although MATLAB appears to have far more capabilities. Scripts in MATLAB are opened for editing by the fitting function 'edit' followed by a space and then the script name and then executed merely by entering the name of the script into the Command Window (this is mostly irrelevant, but this works just like using the "edit" menu on the calculator and then the execution of programs by entering their name into the window). In order for a file to be found by MATLAB, it must be in the search path, which can be altered easily using the "Current Folder" box that becomes part of the MATLAB window if you try to call up a program. There is a drop down arrow on it for adding a folder and various other things, and there is an index at the top of which folder you are currently in, where each folder and sub-folder has a drop down arrow for the selection of any of its sub-folders. If you wish to add a folder, you merely right-click it and click "Add Folder". Now for actually discussing the specifics of "PiggyBank". First of all, the commenting; A "%" at the beginning of a line causes the line to be disregarded by MATLAB and merely an assistance for a human viewer that explains the code. The first new command in this script is 'input'. This command will make MATLAB display the string given in the parenthesis, and then the user is to input a number or a string, which is subsequently stored into the variable the programmer designates. If the programmer does not designate a variable to set the input equal to, MATLAB default in "ans", the same way it does if an operation is entered into the Command Window without any other purpose. Pretty straightforward. Line 4 is a simple mathematical operation of variables. Line 5 uses the 'disp' command, which simply requires a string to display in the Command Window when its value is called. Also in line 5 is the 'num2str' command, which converts a value to a string, which I had to do in order to display the total value after the calculation. Finally, I also learned the concept of grouping strings together using brackets, as shown in the display command. This is one other slight difference from my Java experience; in Java, strings are combined using "+" (for example "Hello" + "World" would read HelloWorld), not by being bracketed together, and numbers are thus converted to strings by this adding method (converting a variable n that contains an integer to a string would be done like so: n + ""). Then, I began my last segment of MATLAB's "Getting Started": "Loops and Conditional Statements" (a sub-section of "Programming and Scripts"). Below is a refined version of PiggyBank that uses some of the concepts from this section. This bolstered version of PiggyBank uses 'for' and 'if' loops to show the user how much the funds would appreciate due to interest. I also cleaned up the original inputs to make more sense. The 'for' loop is no new concept to me - it is a loop that operates multiple times, the number usually governed by a start value, end value, and increment, and often the calculations done inside the loop use the iteration number as a changing variable to take advantage of. This version is very similar to Java's version of the 'for' loop whose parameters are a starting value, a limit, and an increment. I didn't test this, but I'm sure the increment for MATLAB's 'for' loops can be altered as well. The use of the 'end' line to signify the end of the given loop reminds me of the calculator programming, whereas Java would use braces to organize the loops. The 'if' statement is simple enough - it evaluates a condition, and if that condition is true, the code under the 'if' is executed, if not, it is skipped. The 'else' statement is executed if the 'if' condition is not true. 'elseif' is the middle man between 'if' and 'else' - it is checked if the 'if' or 'elseif' statement before it is false, if one of the preceding 'if's is true, the code of the subsequent 'elseif'(s) never gets touched. So, I had the 'for' loop run through and show all of the values for the months of interest, but for the 0th month obviously to put the current value, and for the 1st month make sure to keep things singular. I did not investigate into the 'while' or 'switch' loops, but I know how they would work. 'switch' operates one of a set of actions depending whether the governing 'case' is true, and its fallback is 'otherwise'. 'while' operates like a 'for' loop, but rather than declare an increment of increase and have the governing variable go up a set of values, 'while' loops only declare an initial value, and then do calculations on the governing variable inside the loop (in a 'for' loop, you can't touch the variable in charge of the increment, you can only use it as a component of calculation). Today I left QuarkNet at 6:15.

December 6th
Today I arrived at QuarkNet at 4:00. I began reading the MATLAB textbook. I spent a little time flipping around and glancing at what I was going to come across, and then I got down to business and began reading from the very beginning. The first new thing I learned was the capability of the Workspace to show different qualities of the variables. Below is a screenshot of the options. I feel like the ability to show this variety of features about variables will be vital when I move into precise computing, especially things like showing how many Bytes each variable is when trying to maximize speed in a parallel computing environment. Another useful way MATLAB lets you handle variables is through the Variable Editor. Since MATLAB stores all numerical variables as arrays and even some string variables as arrays, they conveniently can be shown as a sort of spreadsheet, as shown below. This appears to be a very convenient way to visualize data, especially in the case of a matrix, like the first picture. Also, that first picture is a great way to change a matrix variable without having to imagine the entire matrix in your head. The author suggests a particular layout of the various windows in MATLAB, and I agree and feel like this will be an extremely useful way to have things set up. Workspace, Current Folder, and Figures I agree are interchangeable, while Command Window and Editor are necessities. Also, when things begin to get more complex, it is going to be vital that Editor has plenty of space, but equally vital that the rest of the stuff is in the same window, because I already had a hard enough time switching between windows as I wrote and tested PiggyBank, and I can't imagine how annoying it would be for a complex program. Section 1.2 is all about variables. I have already dealt a good deal with number and string variables in MATLAB, but the type I had not encountered until now is 'logical'. Java had its own variable class called 'boolean', but true/false variables are thrown in with the 'logical' group in MATLAB. Below are pictures of the code and the Workspace for one true variable and one false one. It is interesting to note that true is stored as '1' and false as '0'. The next section is about numbers and functions, and was nothing terribly new. Imaginary numbers can be typed by using 'i', scientific notation uses 'e' in place of "x10^", trigonometric functions are adapted to degrees by adding a 'd' before the parenthesis, inverse trigonometric functions are denoted by adding an 'a' in front of the function, exp(x) returns e^x, log10 is a substitute for log base 10, 'factor' returns prime factors, and 'rand' is the (pseudo?)random number generator. Section 1.4 is merely about 'help' and 'doc', which I have already discussed in detail. Section 1.5 addresses the writing of simple scripts, in a similar manner to the way I did with the "PiggyBank" program. It suggests that all programs should be structured as follows: a commented explanation of the program, a block for setting inputs, a block that does the calculations, and a block that displays the results of the program. This section gives some useful programming advice (such as comment comment comment, organize it in a clear way or else even you may get lost in it, etc), but nothing terribly new. Section 1.6 continues with the friendly advice of how to not fall into traps in programming that I learned (sometimes the hard way) in Computer Programming class. Section 1.7 explains the debugger. I became great friends with the debugger when working with Java, so the idea of being able to track variables through each line of code is valuable to me. I had to take a second to get used to MATLAB's debugger, but the ability to watch all the variables through the Workspace makes everything with the debugger very smooth. Below are pictures of the different buttons that can be used during debugging and the green arrow that indicates where the debugger is at in the program (which will be a red dot before the debugger is fired up). The 'step' button allows you to look line by line, and 'step in' allows you to do so piece by piece. Continue lets the program run as usual. That is the end of chapter 1 and also of my day. I finished working at 6:00