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

Develop matlab script Qtn2.m to solve following questions a) Create a column vec

ID: 3874855 • Letter: D

Question

Develop matlab script Qtn2.m to solve following questions a) Create a column vector called odd nums which contains odd numbers in the range 24 to 204 (all inclusive). b) Write a Matlab statement to determine how many elements are there in odd nums vector and assign answer to variable num_elements. Write down the value of num elements as comment. c) Using odd nums vector, create another vector called odd nums desc which contains elements of odd-nums but in descending order. Display odd nums desc. Write down the last five elements in odd nums desc as a comment Using odd nums and with the help of find and rem fiunctions, display all numbers from odd nums which are multiples of 5. How many are they? Write down the answer as a comment. d)

Explanation / Answer


odd_nums = []

%traverse from 24 to 204 and append the odd number to array
for num = 24:204
if rem(num, 2) == 1
temp = [num]
odd_nums = [odd_nums, temp]
end
end

odd_nums = [odd_nums]' %intially mumbers were in row vector form, to make column vector we need to just take transpose of the row vector


num_elements = size(odd_nums) %size returns the size of an array

%value of num_elements is 90

odd_nums_desc = flipud(odd_nums) %flipud reverse array since odd_nums is in ascending order we just need to reverse the array

% last five elements are 33, 31, 29, 27, 25

x = find(rem(odd_nums, 5) == 0) %store the indices of number divisible by 5
odd_nums(x)

p = size(x)

% number of elements divisble by 5 is 18