Problem 1 (2+4+4=10 points). Write a program to play rock, paper, scissor against the computer. The game consists of two players drawing at the same time one of three hand gestures representing a rock, a paper or a scissor. The winner is determined according to the following rules: rock beats scissor, scissor beats paper, paper beats rock. If both players draw the same item, it is a tie.
1.1.) The computer should ask what item you have chosen (rock, paper, or scissor). The input should be entered as a character: r for rock, p for paper, s for scissor. Write your code to account for invalid inputs (by notifying the user the input is invalid and restarting the input prompt). The computer will then randomly draw one of the three items for its choice with equal probability using a random number generator.
1.2.) Next, the computer will determine who the winner is (or if it is a tie) and report the result in the command line using fprintf( ).
1.3.) The user should then be asked whether they want to play again or not. If the answer is y (yes), the game should loop through steps 1.1-1.2 again. Otherwise, the game will stop and the computer will report (in the command line) how many times each player (you and the computer) won.
Problem 2 (4+4=8 points). Consider the function f(x) = exp(22 )cos(8x). Our goal x
is to compute the integral function I(x) = f (x) dx . Use the subplot() command for Figure 1: 2
2.1.) Compute I(x) numerically using Euler integration, (approximating the integral as a sum of areas of narrow rectangles) as discussed in class and using an x increment of 4*pi/50) and plot it together with f(x) in Figure 1, as the left subplot over the range -2*pi x 2*pi and -1 y 1.
2.2.) Compute I(x) symbolically (i.e. using syms or a function handle) and plot it together with f(x) in Figure 1 as the right subplot over the range -2*pi x 2*pi and -1 y 1.
Write a title for each subplot and label the curves and axes accordingly.
Problem 3 (4 points). Solve the following system of equations with MATLAB and display the solution as a vector in the MatLab command line:
3w 2x + y + 5z = 14 3x + 3y 2z = 20
4w + x 2y 2z = 18 w 4x + 2y + 4z =2
Page 2 of 4
Problem 4 (3+4+3=10 points). Download the file FEpics.mat from the Canvas page of the assignment. The file contains two three-dimensional arrays (Frame1 and Frame2), which correspond to two color images taken by a geostationary satellite of the National Oceanographic and Atmospheric Administration (NOAA) on September 13th, 2018. The two pictures were acquired 30 min apart and clearly show the hurricane Florence landing on the Southeast. If youre curious, cool tones indicate high-levels of humidity (water vapor) and warm tones indicate low levels.
4.1.) In Figure 2, display four panels as 22 subplots. The first panel will display Frame1 as a true-color image, the second panel its red channel only, the third its green channel, and the fourth its blue channel. Label the figure panels accordingly, i.e. titles of each subplot.
4.2.) NOAA combines images from different satellites to compute the winds speed and direction. With the images from a single satellite, we can still estimate the wind speed as the change in intensity in the red channel, which is the most sensitive to humid air density:
Wind Speed = Red Channel Frame 2 Red Channel Frame 1 (approximately)
In Figure 3, display two subplots in one row. The first one will display Frame2 as a true- color image and the second the wind speed in arbitrary units. Label the figure panels accordingly and add a colorbar to the right figure.
4.3.) Find the location of the maximal wind speed and overlay a red cross (with linewidth 2) at that location in both subplots of Figure 2.
Page3of4
Problem 5 (4+4+5+5=18 points). In this problem we will use a simple machine learning algorithm to solve a classification problem. The problem setup will be described step by step, but the method only uses plots, functions, and distance calculations that have been used in previous lectures and labs.
5.1.) Input the following material information into a table:
Material: Gold, Silver, Iron, Lead, and Copper (Row names for the table) Densities: 19.320, 10.490, 7.850, 11.340, 8.940 (g/cm^3)
Electrical Conductivities: 4.52, 6.30, 1.04, 0.487, 5.98 (x10^7 S/m) Thermal Conductivity: 318, 428, 83.5, 35.5, 401 (W/m*K)
We will use this table in a very simple classifier algorithm. You will treat each value as a location in space and determine the distances of new measurements as compared to the known values in our table.
5.2.) In Figure 4, display the materials locations in 3D space using the scatter3( ) plot, where your X-dimension is Density, Y-dimension is Electrical Conductivity, and the Z-dimension is Thermal Conductivity for each material. (This should help you visualize the abstract space we created, obviously any more than three dimensions and we cannot visualize it anymore)
For example, to plot Gold, you would plot a point at scatter3(19.32, 4.52, 318)
However you will need to use the table index to call on these properties for plotting, for example, Metal.Density(1) for the density of Gold for a table, which is our x-value for Gold in a table named Metal). Dont forget to use hold on for each point you plot and add a legend with the metal names matching the points. Hint: (a for loop may be useful, but add the legend after the loop)
5.3.) We now have a new material that we measured Unknown Metal #1: [14.2, 6.4, 70]
And we arent sure which known material it is, so we will use a distance formula to estimate which known metal it most closely resembles. (You do not have to add this unknown metal to the table). The distance formula is:
dist = sqrt((xk-xu)2+(yk-yu)2+(zk-zu)2),
where u means unknown metal value, and k means known metal value.
So, we have to use the distance formula for each known material to find the distance our new material is from each known material. (You might want to plot this new point to see where it is located relative to our known metals)
Page 4 of 4
1. Create a new table column called Distance that stores this value for each known material (initialize the values as zeros).
2. Calculate the distances of each known metal relative to the unknown metal, a for loop will make this easy.
3. Find the minimum Distance and the material that it resembles (you may want to use the [M I] = min() function so you can track the index value (I) at which the minimum distance (M) occurs).
5.4.) Generate a function that performs the steps #2 and #3 of 5.3 called Material_ID(), where the input to the function is the table of values defined in the problem setup and the Unknown Material triple and the output from the function is the specific material that the classifier function identified as the known material to most resembling the input material triple. (Assume that the Distances column is already in the Table before being input into the function. The function may be defined in your script, but it must be defined at the end of the script)
Use this function for two more unknown metals given the following values in order and display the results with disp(Metals.Properties.RowNames(x)) after each iteration of the function call:
Unknown Metal #2: [21.2, 3.2, 120] Unknown Metal #3: [11.4, 2.1, 49.2] Unknown Metal #4: [15.3, 5.2, 400]
Page3of4
Reviews
There are no reviews yet.