Wednesday, September 30, 2015

MATLAB Day 4

Trig Functions



     We get into some more basic functions in MATLAB. These functions are trig functions. We are able to create a vector of numbers and insert these numbers into the function to produces a vector of solutions. some of the basic functions require the input to be in radians instead of degrees, but there are functions in MATLAB that allow use to input degrees. Otherwise, we can also create a command that converts between degrees and radians.


   We show some more basic functions. This shows that MATLAB is able to handle arccos and arcsin. The function is a simple asin( ) or acos( ). To input the degree instead of radians, the command would be sind( ) or cosd( ), where the d tells MATLAB that within the trig function is a number in degrees.


   We explore MATLAB using the trig functions and try to input the cosecant trig function. I, first, make a conversion between degrees and radians, and make this conversion into a variable. Then, I try to find the cosecant of that angle in radians. At first, I spelled out cosecant completely, but MATLAB gave me an error, showing that this command was not in the library.


   I utilize the help command that is in MATLAB to help determine the command used for cosecant. This command is the same as the abbreviation of the trig function. On the other hand, I may also use the function for sine and make that solution over 1, just like the definition.

Applications For Trig Functions




   We, then, use trig functions in MATLAB to create a simple program that would solve for a specific problem in physics that involves forces. We are given the forces acting on a balloon and the direction these forces are pointed. Using Newton's Laws and the trig functions in MATLAB, we are able to break all vectors down to their components and solve for the net force actin on the balloon. There is also some commenting displayed for practice.

Finding Max, Mean, Median, Mode of a Matrix


   We look at functions in MATLAB that allow us to find values within a matrix that are max values. The max command finds the maximum value according to the column. We can also have MATLAB be more specific in the response for max values. We can display the max value and the row that the max value is in. Since the max alue is in reference to the columns, we don't need MATLAB to say which column the max value is in.


   We can find the maximum value of the entire matrix by using the max function within the max function. This finds the max according to columns and the uses those values to find the max within that set. Using the mean function works the same as the max function. It finds the mean, or average, of the values within a column.


   The mode function allows us to find which number occurs the most often in a column. We can also transpose the matrix and solve for the mean median and mode. This requires an apostrophe at the end of the variable for the matrix. Just like the max, we can find the total average of the entire matrix by using the mean function within the mean function.


   Sorting the matrix by the in order from smallest to largest can be done using the sort function. We can also tell MATLAB to sort the columns in order by using the sortrows command.


    MATLAB automatically sorts the columns in ascending order, but we can have MATLAB sort in descending order by including 'descend' after the matrix we are trying to put in order.


   When making a larger matrix, we can manipulate the matrix in the same manner. If we want to put a column in ascending order, we can use the sortrows command. Within the sortrows command, we state the matrix we are trying to sort and the column we want to sort. Just like before, we can choose whether the columns are descending or ascending.

Summary:
   We discussed some of the trig functions available in MATLAB. MATLAB does not seem to be picky on whether we use degrees or radians, as long as we call the right function. We also went over some of the applications of trig functions, such as forces in physics. We finished off by examining some functions that help us find the maximum, the mean, the median, and the mode of a set of numbers in a matrix. We found that these functions are predefined to find the mean, median, mode or max of columns. 


No comments:

Post a Comment