Oct 13, 2015

HW#11

Most of the problems were fairly easy to do, almost on-par with the practice exercises from in class.

Questions 1 and 2: practice exercises (pretty much)


Question 3: Simple encoding
I used if statements inside of a while loop to change the odd and even elements into different characters. The odd elements had a different type of encoding than the even elements. Also used was a menu() function to ask the user if they want to decode the text.








Question 4: Planetary data
Practicing struct arrays
Question 5: Cell arrays and extracting data

Oct 8, 2015

Lecture 12

This is an engineering class and not a programming class, so we are now going over data types 6 weeks in. The picture below is from the lecture notes. It shows the various data types MATLAB matrices can store.

realmax() and real(min) gives the maximum and minimum value a double precision floating point, which is the default number data type in MATLAB, can hold. 
Using single() and double() to convert numbers to single and double data types respectively. 
Practice exercises:
Not shown in screenshots, but we went over sparse arrays, cell arrays, and structure arrays. Very cool. I had previously used cell arrays when I used dialog boxes to ask for user input. I have only used structs one time to implement doubly linked lists in C++. 

HW#10

Question 1: Solve a system of 7 equations. Use tic() and toc() functions to test whether matrix left division is faster or matrix inverse is faster. The notes said that left division was generally more accurate and faster, but in this case the inverse was faster and both gave the same results.















Question 2: This question was similar to the desalination question from the example in class. The most difficult part was figuring out how to solve for the third unknown. It took a few minutes, but I finally realized that the third variable x could be moved to the right-side of the equations. The first equation would have a 0 in place of the coefficient for x.
Question 3: Similar to the truss example from class, but with a force applied at an angle. I just modified the program from class to allow the user to enter the force applied and the angle at which it was applied.
All of the problems could be solved using a generic function ask_matrix(). It asks for the amount of unknowns needed, then uses two while loops to allow the user to enter in the appropriate amount of coefficients. The, the user is prompted to enter the answers to the equations. It will return two matrices, one containing the coefficients, and one containing the answers (which is transposed). I could also have it calculate the unknowns with 1 extra line of code.

Oct 6, 2015

Lecture 11

Mahmoud's Matrices continued...

Context example: calculating the electrical current. Ask for user input for values of resistance and voltage



This first program uses inverse and matrix multiplication.



Changing line 16 from the first program to use left division instead of inv(). It shows the same results.

Context example: desalination



















More or less the same as the electric_current.m program.

Context Example: A force on a statically determinate truss.
































The same concept as the other problems, except with 6 equations and 6 unknowns. The process is more or less the same.

Using eye() to create identity functions.
pascal() and rosser

HW#9

Question 1: 
Question 2:

























Uses mtimes to calculate the total heat capacities for each experiment. Then, there is room for the user to input their own vector containing the respective masses for water, steel, and aluminum to find the total heat experiment.

Question 3:







Uses function inversed() to check if a square matrix has an inverse by checking if the determinant is 0. 

Question 4:

Oct 1, 2015

Lecture 10

We are going over using MATLAB to solve linear algebra.



The first thing is the real dot product, instead of the dot multiplication (.*) product we have been using. dot(A,B) does the same thing as sum(A.*B)  with one less character.
Using A∙B = |A||B|cos(theta) and dot product, calculate theta between A = 5i + 6j + 3k and B = i + 2j + 2k.




Using dot product on different column vectors of the data matrix to calculate the position of the center of mass.

















There is no screenshot, but we also went over dot product with multi-dimensional matrices.

Practice exercise for inverses
A matrix multiplied by its inverse results in an identity matrix. Not shown is the determinant function det().



This exercise uses cross product to calculate the moment about a pivot point on lever for a given force that is described as a vector.


HW#8

Question 1: Free fall
We had previously done a free fall question, but I focused more on the GUI and graphical aspect of this program. The actual code took around 5 minutes, but I spent most of my time figuring out the RGB codes to match the colors of the different celestial bodies.





Question 2: Practice exercises
Using matrices and manipulating them. Also the magic() function. I created a function magical() to test if a specific matrix was still a magic matrix.




Lecture 9

Today, we switched professors from Professor Mason to Professor Mahmoud.
I think we're going to go over simple data structures.

We started with the different ways of defining matrices.

1) Assign to the variable x1 the value in the second column of matrix a.
2) Assign to the variable x2 the third column of matrix b. 3) Assign to the variable x3 the values in matrix b along the diagonal.
4) Assign to variable x4 the first three value in matrix a as the first row and all the values in matrix b as the second through fourth row.

This shows that we can use the matrix(row number, column number) format to find a specific value in a specific row and column. You can also use a colon ':' to indicate any row and/or column.



This exercise lets us practice manipulating matrices. This program finds the maximum and minimum temperatures for each thermocouple. Then it creates a table showing the maximum/minimum temperatures with corresponding times.


In this practice exercise, we used meshgrid to find the areas of rectangles with lengths 1, 3, 5 and widths 2, 4, 6, 8.






This exercise lets us multiply all of the elements in one vector by all elements in another vector by using meshgrid(). More details in the comments.

Practice exercises