Friday, September 11, 2015

MATLAB Day 2


Introduction To MATLAB


   We begin experimenting with MATLAB by running some simple calculations. We found that MATLAB can handle these calculation very well, as it follows the order of operations in basic algebra.


   On a whiteboard, we wrote down a calculation for a desired result from the professor. We, then, traded boards with another group. Once our boards were traded, we inputted exactly what was written on the white board. The white board we received did not properly write their arithmetic so that MATLAB could solve it correctly. This demonstrates that MATLAB is sensitive about how calculations are inputted.


   We start taking a look at simple matrices. First, we input a matrix defined as B two different ways. One way, we use commas, while we just use spaces for the second way. Both methods were defined by B. We found that either way produces the same exact matrix. By exact, we mean that the matrix has double data type and takes up the same amount of space. After, we state a 3 by 4 matrix C using the semi colon. Semicolons allow us to move to the next row of a matrix.



   We take a look at some plotting abilities that MATLAB has. By defining x to be a simple matrix set and y to be a different matrix set, we use the plot function to plot a liner graph. The graph displays a bunch of values and a line. After, we go over some of the ways to create good variables. Variables are important because it allows other programmer to get an idea  of what the variable means. In this case, different variables are created to calculate area, surface area and volume. Also, by placing a semi colon at the end of the statement, MATLAB is suppressed by not displaying or restating what was written in the command window.

Less Typing For Less Errors


   We continue practicing by stating variable and solving for a function, but we do so a different way. To avoid any errors in calculation, it is best to do as little typing a possible. We are able to do this if we see any common pieces of arithmetic in the equation and just create a simple variable for that piece, that way, instead of typing so much arithmetic over and over again, we can type something like A. It is also shown that the letter a was used twice. MATLAB recognizes capital and lowercase as different characters and therefore, we are able to use the same letter twice as a variable.


   We go over an ideal gas problem next. The idea here is to do as little typing as possible again. We do this when we have to change the temperature. We do this by pressing the up key on the keyboard. We we press the up key, we are able to refer back to the previous commands we inputted and reuse them. This saves us from make any calculation errors by pressing fewer keys.


   In MATLAB, we can generate a set of numbers using different commands. The first command uses colons in between numbers. For example, by typing 0:2:10, we are able to generate a set of numbers between 0 and 10 going by twos. This command requires the first number first, the last number last, and the type of arrangement for the the numbers in between in the middle. We also use a command called linspace. This command allows us to choose the first number, then the last number, and the spacing of these numbers. For example, the numbers between 10 and 20 with five spaces in between is generated in the picture. This command calculates the numbers in between and these numbers are evenly spaced. The final command is the logspace command. This commant works similar to the linspace, excect it deals with orders of ten. The first input would be the first power of ten. The second input would be the second power of ten. We are only putting the powers when inputting. For example, if we want our first number to be 100, we input 2 for 10 to the power of 2. The last number, like linspace, is the spacing in between the two values. Also, we are able to clear all of the previous data from before by typing "clear" and we are able to work on a fresh page by typing "clc".

Matrix Algebra



MATLAB is great when it comes to matrix calculations. When stating 2 matrices, it is important to remember the principles for matrix algebra. For example, when we multiply two matrices together, we have to distinguish it by telling MATLAB it is a dot product calculation. We can do this by putting a period in front of the multiplication symbol. MATLAB, then does the calculations. If this is not done, MATLAB will state an error. We get some practice with matrix calculations by knowing when to implement the period.


   MATLAB can also transpose a matrix. In order to transpose a matrix, a apostrophe needs to be put immediately after the variable that represents the matrix. This is useful, not only for linear algebra aspects, but for creating neat tables.

Computational Exercises



   This exercise was in reference to the tragic event that took place on mars, when the Mars Climate Orbiter burned up in the orbit of Mars due to conversion errors, costing a great amount of money. We use our white boards to plan how we would tackle the problem on MATLAB. We converted pounds to newtons and created a table for comparison. This demonstrates how easily this could have been avoided. MATLAB was able to convert using minimal commands. Also,, MATLAB has the ability to guess what commands a person really wanted but did not get because of typo errors. Not only that, it retypes everything and all a person has to do is press enter.



   The final problem to solve involved a conversion between miles per hour to velocity. On our white board, we come up with a way to solve the problem with the givens. We calculate the answer by hand and compare this calculation to the answer on MATLAB. With the given information, we had to find the coefficient of drag with at a certain speed and at many different speeds. This was done fairly easily with MATLAB.

Summary:
   Today, we went over some of the basic computational aspects of MATLAB. We found that MATLAB follows the order of operations. We, also, found that MATLAB contains the ability to plot a graph. MATLAB specializes with matrices and we saw a glimpse of how powerful MATLAB is when it comes to matrix calculations by crating and transposing matrices, multiplying them using the dot product, and even coming up with a set of numbers. We are able to utilize MATLAB to make conversions between units

No comments:

Post a Comment