Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

BE 1500- Exam 1 (200 Points Total-170 in class /30 online) (30 points) Matiab: W

ID: 2074758 • Letter: B

Question

BE 1500- Exam 1 (200 Points Total-170 in class /30 online) (30 points) Matiab: Write a script that uses the colon operator, linspace AND other built-in MATLAB functions to create the matrix of the numeric data shown below. 1. 23 2 12 15 24 23 6 22 13 23 18 3211 23 54 42 23 162 52 30 36 42 48 Now within the script use MATLAB commands to make the following changes to the matrix: 1. Replace the 2nd and 3rd row in the 5th and 6th columns with ones. 2. Replace the element in the Srd row and 4th column with a zero 3. Replace the entire 1st row with zeros. 4. Sort the matrix in ascending order along columns. 5. Transpose the matrix sult Next, the script should calculate the sum of the resultant matrix from previous step, your re should be one number Perform the following calculation, where sum_of matrix is the output from the previous step Output-Answer = 10.sun_of_matrix/ 12 + 15-sum-of-matrix^ 2 (60 pts) Write a script that asks the user to input an age and a monthly income. The script should then do the following: 2. Use the Switch Case construct to calculate the retirement savings based on the table below. Use If-Else to calculate the retirement savings based on the table below. For both protect the case when user enters negative income and negative age. a. b. c. i. Negative Income: Output for savings goal should be 0 i. Negative Age: Message "Invalid Age Input" Retirement Goal by Age Age Less than 30 Between 30 and 40 Between 40 and 50 Between 50 and 65 Greater than 65 Saving Income entered by the user 3 times income entered by the user 5 times income entered by the user 7 times income entered by the user "Stop Saving Start Spending" V4

Explanation / Answer

code:

clc
clear all
% create the matrx
A = rand(5,5);
A (:,1) = 23;
A (:,2) = 2*3.^(0:4);
A (:,3) = linspace(12,52,5);
A (:,4) = linspace(15,7,5);
A (:,5) = linspace (0,4,5);
A;


A (5,4) = 0
A(1,:) = 0
B = sort (A) % sort along column
C = B' % transpose
D = sum (C);
sum_of_matrix = sum (D)
output_answer = 10* sum_of_matrix/12 + 15 - sum_of_matrix^2

ans:


A =

23 2 12 15 0
23 6 22 13 1
23 18 32 11 2
23 54 42 9 3
23 162 52 7 4


A =

23 2 12 15 0
23 6 22 13 1
23 18 32 11 2
23 54 42 9 3
23 162 52 0 4


A =

0 0 0 0 0
23 6 22 13 1
23 18 32 11 2
23 54 42 9 3
23 162 52 0 4


B =

0 0 0 0 0
23 6 22 0 1
23 18 32 9 2
23 54 42 11 3
23 162 52 13 4


C =

0 0 0 0 0
23 6 22 0 1
23 18 32 9 2
23 54 42 11 3
23 162 52 13 4


sum_of_matrix =

523


output_answer =

-2.7308e+05