Linear ALGEBRA matlab
Posted: Mon May 02, 2022 4:56 pm
Linear ALGEBRA matlab
4. Problem on PCA Suppose were volunteering at an MSPCA animal shelter for your summer job, and you were charged with feeding, grooming, and keeping track of both the length and weight of 5 resident cats. Cat ID x1 = Length (in) x2 = Weight (lb) ) 1 4 3 3 2 10 7 3 15 6 4 18 8 5 13 6 Table 1: You were monitoring and taking care of these 5 cats for the summer! Suppose we let: Factor x1 = Length (in) Factor X2 = Weight (lb) a) Using matlab, calculate the means for factors x, and X2, where: mi = mean of Factor xı (length) Report this result your matlab command window. m2 = mean of Factor X2 (weight) b) Using matlab, construct matrix A (or D) by: First subtract the data vector x, by my, and inserting the result as the 1st row vector in A (or D). Then, subtract the data vector X, by my, and insert the result as the 2nd row vector in A (or D). Then, calculate the sample covariance matrix S. 1 1 S= AAT n-1 or S = DDT Report this result your matlab command window. n-1 ENG EK 103: Problem set 11 Due date: April 30, 2019 (Tues) c) Using matlab's eig function, calculate the eigenvectors and eigenvalues of the covariance matrix S. Report the eigenvalues and eigenvector matrices in the command window. Then, make a printout of a screenshot of the combined command window outputs from Parts (a -c). Turn the printout in with your homework. d) Using matlab, do the following (plotting tasks) Create a xz vs x plot of your original data points (Remember: We always refer the axes of scientific plots as: y-versus - ). *** IMPORTANT: Be sure to include the command axis square somewhere near the end of your script. This will make your grids square, and you will be able to draw the perpendicular eignevectors of S more accurately at a later step. . Make sure the axes are clearly labeled (ie. "x1 = length (in)" and "x2 = weight (lbs)" ) • Make a printout of your plot a Then, using your pen or pencil, mark the data set's centroid point (m, m2) on your plot Suppose the 2 eigenvectors of Swere normalized to unit vectors 1 and 72. Using your pen/pencil and a ruler, draw the 2 eigenvectors of S (scale them up so that their lengths are at least 41 and 472 when you're drawing them on your plot). Using your pen/pencil, indicate which is the dominant principal axis of your data set. Turn in your completed plot with your homework! Hint: Since the covariance Your eigenvectors should be perpendicular lines that travels through the centroid point (mu, m2)
4. Problem on PCA Suppose were volunteering at an MSPCA animal shelter for your summer job, and you were charged with feeding, grooming, and keeping track of both the length and weight of 5 resident cats. Cat ID x1 = Length (in) x2 = Weight (lb) ) 1 4 3 3 2 10 7 3 15 6 4 18 8 5 13 6 Table 1: You were monitoring and taking care of these 5 cats for the summer! Suppose we let: Factor x1 = Length (in) Factor X2 = Weight (lb) a) Using matlab, calculate the means for factors x, and X2, where: mi = mean of Factor xı (length) Report this result your matlab command window. m2 = mean of Factor X2 (weight) b) Using matlab, construct matrix A (or D) by: First subtract the data vector x, by my, and inserting the result as the 1st row vector in A (or D). Then, subtract the data vector X, by my, and insert the result as the 2nd row vector in A (or D). Then, calculate the sample covariance matrix S. 1 1 S= AAT n-1 or S = DDT Report this result your matlab command window. n-1 ENG EK 103: Problem set 11 Due date: April 30, 2019 (Tues) c) Using matlab's eig function, calculate the eigenvectors and eigenvalues of the covariance matrix S. Report the eigenvalues and eigenvector matrices in the command window. Then, make a printout of a screenshot of the combined command window outputs from Parts (a -c). Turn the printout in with your homework. d) Using matlab, do the following (plotting tasks) Create a xz vs x plot of your original data points (Remember: We always refer the axes of scientific plots as: y-versus - ). *** IMPORTANT: Be sure to include the command axis square somewhere near the end of your script. This will make your grids square, and you will be able to draw the perpendicular eignevectors of S more accurately at a later step. . Make sure the axes are clearly labeled (ie. "x1 = length (in)" and "x2 = weight (lbs)" ) • Make a printout of your plot a Then, using your pen or pencil, mark the data set's centroid point (m, m2) on your plot Suppose the 2 eigenvectors of Swere normalized to unit vectors 1 and 72. Using your pen/pencil and a ruler, draw the 2 eigenvectors of S (scale them up so that their lengths are at least 41 and 472 when you're drawing them on your plot). Using your pen/pencil, indicate which is the dominant principal axis of your data set. Turn in your completed plot with your homework! Hint: Since the covariance Your eigenvectors should be perpendicular lines that travels through the centroid point (mu, m2)