Monday, October 5, 2015

MATLAB Homework 4

Problem 1


   For the first problem, we observe some mechanics of materials. We are given a table of a load, in pounds and the corresponding displacement due to the load. There is a correlation between the load and the compression. In order to observe the relationship between the stress and the strain, or the displacement of compression, we solve for the strain and stress using the equations for stress and strain. Since we are working with an array of numbers, we should be getting an array of solutions for the stress and the strain. These arrays will have the same dimension, and, therefore, we are able to get the strain and the stress plotted on a graph. The graph shows that the is a linear relationship at first, then, there is a change. This change occurs at the yield point. The linear slope is the elasticity of the object that is compressed. Using this graph, we are able to see how far we can compress or stretch an object.

Problem 2


   The second problem has us working with polar graphs. The first graph is a three flower pedals with a large radii and 8 flower pedals half the radius of the overlaid 3 flower pedals. We can acheive this picture using the hold on command. This command allows us to put multiple functions ont eh same graph. The second graph is a heart. The third is a 6 pointed star. This is achieved by plotting less points. With less points, we can achieve straight lines. The last graph builds off of the idea of the star. The only difference is how the lines connect from on position to another. 

Problem 3


   The third problem has us look at the transistor count for the Intel processor on a periodic basis. In the program, I create an array of the years and time in years of 2 year intervals to match the year array. Next, we use the formula that calculates the transistor count. This is a theoretical model. The theoretical model will be used to compare to the actual count. Before we compare, though, we create some graphs for the transistor count vs. time. We utilize the different ways to plot, such as the semilog or the loglog plots.


   Once the graphs of the theoretical values are plotted, we then choose the type of graph we want to show to compare the two slopes. Since we want to see a simple representation of the rate at which the transistors increase with time, we force the data to plot a linear graph using the loglog plot. The plots, by comparison, show that the transistors increase at the same rate. This means that the theoretical equation does a good job n predicting the transistor count. 


MATLAB Day 5

Graphing By Plots


   We go back to the idea of plotting on MATLAB. We can create a variable and make it into an array and create a second variable and make it into an array. Using the plot function, we can plot a graph based on the arrays. One condition is that the arrays have to be the same size. The plot command plots the x-axis first, then the y-axis. Once we plot the graph, we can add some details. We can use the title command to give the graph a title and the xlabel function to label the x-axis. The ylabel function works the same way.


   We establish an array of angles so that we can graph the functions of sine and cosine with respect to the angles of the array. This introduces the subplot feature that allows us to look at two graphs, simultaneously, on the same window. This is a good feature for comparison purposes.


   The next feature for plotting is the hold on/off command. Selecting to hold on during plotting allows us to plot a second graph, a third, a forth, and so on, on the same graph, until we select the hold off command.


   We can also alter the graph by altering the point designs, the line design, and color of the line. We make these alterations within the plot command.



   In the next problem, we look at saturation vapor pressure. The relationship between the pressure and the temperature is given by a logarithmic. On our white boards, we refined the equation to solve for the saturation pressure, given the other pieces of information.


   We create an array of temperature values in kelvin for the problem on the whiteboard.


   More values are created in variables. We, then, use the given values to find the saturation pressure using the equation derived on the whiteboard. Since we are working with some arrays of numbers, we have to remember to account for the dot multiplication. For the amount of temperatures there are, the result displays the saturation pressures for every temperature.


   After all of the values for saturation pressure have been calculated, we plot the graph pressure vs. temperature. The graph correctly shows us an exponential change as the temperature increases.


   The next problem involves a standard projectile motion problem. The projectile in this problem shoots at an angle on a level surface and lands on the same height. Using the x-component and the y-component, we manipulate the kinematics equations t solve for the range a projectile travels.


   We start the problem on the whiteboard by giving an initial velocity of value 100. We are to create a simple program that calculates the range an object travels at angles launched from 0 to 45 degrees.


   Once the givens have been established, we create the equation to solve for the range a projectile travels at different angles launched. Again, we have to make sure that we account for the arrays that are in the equation.


   We draw the graphical representation of the values we calculated. As the angle increases, a parabolic behavior representing the distance traveled is displayed. The parabolic behavior occurs due to the flight time. We maximize our distance when we attain an angle of 45 degrees, which shows in our graph.


   The ability to do polar graphs is also available in MATLAB. The polar function in MATLAB is reliant on the radial distance, as well as the angular distance, which is how polar is traditionally done. We are able to graph polar graphs seen in calculus classes. To produce smooth curves, we need a large amount of points and radii so that we can graph smooth curves.


   We can make some interesting designs by manipulating the amount of radii and the angle plotted. The less points, the more straight lines that will form when plotting. We can make hearts, flowers, an infinity symbol creating two flower pedals and stars.


   Lastly, we go over some unique plotting abilities in MATLAB. We can plot using the semilog command, which allows MATLAB to find logarithmics of negative numbers and zero, omit these values, and plots around them. This is useful for avoiding errors.

Summary:
   A lot of graphical abilities were defined. We discussed ways to plot many graphs on one window. We also discussed ways to plot multiple lines on the same graph. What we can also do is plot different graphs on different windows. This function is the figure function. We just type Figure(#) where we number the window. We go over some physics problems and plotted the solution. We can also customize the graphs by changing the line color, the points on the line, and the line structure. We finished of by going over the polar graphing and the logarithmic graphing.

MATLAB Homework 3


Problem 1


   For the first problem, we had to create a distance calculator using the coordinate system. The calculator has the user input coordinates on Earth and these coordinates are stored into variables for calculations. This calculator only calculates distance on the norther hemisphere of the Earth. When the user inputs the coordinate of two places, the programs displays what calculations took place. What happens in the program is that the coordinates inputted are converted to spherical coordinates. Once we have the spherical coordinates, we convert these spherical coordinates to rectangular. With these rectangular coordinates, we can do some vector calculations involving the definition of the dot product. The dot product allows us to find the gamma between the two vectors. Once we have the gamma, we can, then, find the distance between the two places using the definition of the arc length, which is the angle in radians times the length of the radius.


   The picture above shows the results of the program for distance calculations

Problem 2

 
   To begin the second problem, we begin by inserting a matrix into MATLAB. We can do this just by using the import command. We can also create a dimensionless matrix in the workspace and make changes to the matrix by copying and pasting the matrix data from excel.


   Using the matrix created, we had to find the maximum values of each column, the minimum values of each column, and the maximum values of the entire matrix. The columns represent the thermocouple temperatures. This problem was done by creating separate arrays from the given matrix and labeling these arrays by the column they represent. One the arrays are created, I am, then, able to mind max values using the max command and minimum values using the min command. To find the max value of the entire matrix, I simply find the max of the entire matrix first. This would give me an array of maximum values. I, then, use the max function, again, to find the max value of the max values. So, I use the max function within the max function.


  The results of the program are displayed in the picture above. The max values of each column are represented by x variables and the the minimum values are represented by y variables. The largest variable shows the largest number of the entire matrix.

Problem 3


   For this problem, we had to create an array whose average was 80 and whose standard deviation was 23.5. We obtain the average by adding 80 to the matrix of random numbers. We obtain the standard deviation of 23.5 by multiplying the array by 23.5.

Problem 4


   We take a look at a circuit problem. The problem has some givens and equations. We simply state the givens and calculate using the equations and the givens. This problem emphasizes imaginary numbers, which are seen in circuit analysis.

Problem 5




   The last problem had us calculate the precipitation of a time period from January 1, 2015 to September 3, 2015. The obtained from the website was a simple 241 by 2. Like the first problem, I broke down the tables columns into arrays. Then, I summed the values for precipitation and found a value in decimeters. We also had to use the first program to compare different stations according to their coordinates and choose the station closest to home. 

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. 


Sunday, September 13, 2015

MATLAB Homework 2


Classwork



   These are the problems that were not able to be done in class and was assigned as homework. It required us to factor, find the GCD, find prime numbers, find the factorial, and find the maximum number of ways to arrange a group.

Problem 1 & 2


   In problem 1, we had to use different functions and compare these functions. When finding the square root, we have three different commands to use. One out of the three commands cannot find the square root of a negative number. This command is the nthroot command. If there was a negative number, the command would display an error. These commands can also handle vector calculations.

Problem 3


   For this problem, more commands were used to divide a vector, find the remainder, find the exponential, and the sin of that vector. The commands used are displayed on the picture.

Problem 1 (4)


   In this problem, the population rate needed to be solved. The givens are initially stated as p_o for initial population, r for the rate at which the population grows or decays, and t for the time the population grows or decays. Next, I input the formula to solve for the current population and labeled this variable as current_population.


   The same idea for the last problem is used for this problem as well, except the variables are adjustable. I used the same variables to represent the same things. I, then, use the input command to allow a user to input the following information needed. The input command is also descriptive on the type of information that it requires.


   This shows the results of the previous commands, once the user inputs the information. At the end, there is a statement that shows how many people there are in the amount of years requested at the rate inputted.

Problem 2 (5)


   For problem 3, a set of numbers were given for heat. Using what we know about heat and the rate at which heat is extracted, the number of A/Cs was determined. I started by stating some of the givens and multiplying some of the givens by the amount of objects that emit heat. I added all of the heat together to get a total of heat entering the home. Then, I calculate the amount of A/Cs needed using the amount of heat an A/C can extract and the total heat going in the home. I finished everything with simple statements that organize the results.


   A similar program as the previous one is implemented. The difference is that now the user can input values for the amount of light bulbs and the amount of appliances. This was done by using the input function for the number variables under the light bulb and appliances. 

Problem 3 (6)



   The final problem involved a bit of discrete math. The first command solved for the number of ways to group 4 people. The second command solved for the number of ways to group 28 students in groups of 7. The third command did the same but with consideration of order. The forth command displayed the amount of ways to get hands of 5 in a 52 card deck. The last command displays the chances of getting a royal flush.

MATLAB Day 3


Using The fprintf Command


   The fprintf command allows us to send send the data from our table t the command window and organize it. We are able t create sentences that give more meaning to the information.There are, also, other useful commands, such as the \n command, that we may use within the fprintf command to make adjustments to the format. \n causes the next line below to be used immediately after. This is why each sentence contains it's own row.

Saving Work And M-Script


   Within the command window, we are able to save and load work using the save and load commands.


   We begin to use the M-Script file capability. This capability is the preferred method for doing work on MATLAB. To begin work on the M-Script, we simply choose "new script" on the top left corner of the program and the program opens up a tab in the middle of the program. In this tabe, we are able to write commands similar to that of the command window. The only difference is that once enter is pressed, the command is not initiated. Like programming, the commands are pre-written and when the user wants to implement the commands, he/she just simply presses the "run" tab and this tells MATLAB to run the commands in the command window. We are also able to save any commands that were written in an m-file. This allows the user to save all the work done. Also, like in standard programming practices, notes can be inputted using the percent key. This allows for other users to understand what was done and to better organize the work.

Problem Solving Using M-Script


   We take a look at equations for velocity and acceleration. All we have to do is plug in the value for time to get the speed and acceleration at that very moment.


   Using the same problem on the white board, we create a set of values for time and input it in the equations for velocity and acceleration. We create a table and used the fprintf command to create well documented answer.


   Next, we take a look at the definition of power and its relationship to velocity and force. Using this relationship, we are able to solve for the acceleration at two different velocities.


   We take the power problem to MATLAB. This time, we start to look at the input command. With the input command, we are able to create a program that will calculate the acceleration of a moving object with fixed values for power and mass. The input allows another user to run the program ind input a value, in this case, for velocity. Once the user input the value, the program calculates the acceleration.

Summary:
   We discussed some of the way to display messages on MATLAB using the fprintf command and utilizing these messages to display important information in a legible manner. We also go over some of the techniques for saving and documenting any work on MATLAB. M-Scripts provide a convenient way to keep track and save any work done on MATLAB. We do some simple calculations to get the hang of M-Script and finish off by utilizing the input command. This command allows a user to input different values in a program without messing with the actual program.