Question: WSU EE221 Numerical Computing for Engineers Fall 2018 HW #12 1. Create a new script that is called HW12a.m and save it. Define X, a

WSU EE221 Numerical Computing for Engineers Fall 2018 HW #12

1. Create a new script that is called HW12a.m and save it. Define X, a random vector of size (20,1). Define a separate for loop for the following problems.

a) Using single for loop, add all elements of X and assign the sum to a new variable Y1.

b) Using single for loop, add all odd elements of X and assign the sum to a new variable Y2.

c) Using single for loop, multiply all elements of X and assign the product to a new variable Y3.

d) Using single for loop, multiply all even elements of X and assign the product to a new variable

Y4.

e) Using single for loop, find all elements of X that are multiples of 3 and assign those elements to a

new column vector Y5.

f) Using single for loop, find all elements of X that are multiples of 2 or 3 and assign those

elements to a new column vector Y6.

g) Using single for loop, find all elements of X that are multiples of 2 and 3 and assign those

elements to a new column vector Y6.

2. Create a new script that is called HW12b.m and save it. Find the submatrix within a matrix

2135

a) DefineA= [1 3 6 7],B=[2 5] 3259 81

6814

b) Use two nested for loop to find out if B is a submatrix of A or not. Use disp command to displayyes if B is a submatrix of A and no if B is not a submatrix of A.

c) In the same script and within the same nested loop, if B is a submatrix of A, replace all elements of that submatrix with 0.

2135

ThenewAshouldbe-[1 3 6 7] 3009

6004

d) Assign 3rd row of A to row vector V.

a) Write a for loop that assigns all odd values of V to a new row vector OV.

b) Write a separate for loop that finds the maximum odd value of V and assigns the maximum odd

values to maxV. (Dont use max command)

c) Write a separate for loop that finds the square all elements in V and assigns that to a row vector

sqV. (Note that sqV will be 1x4).

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!