Please use MATLAB to solve the following problems Be sure to

Please use MATLAB to solve the following problems. Be sure to include well detailed comments so that I can understand all functions and processes. Be sure to answer all problems. Thanks in advance.

Problems In this lab, use MATLAB. You must implement all functions 1. Factors of a Number (30 points) Write a function called FactorsOfNumber that takes as input a positive integer and returns the factors of the positive integer as an array. For example, if the integer is 6, the output is an array consisting of the values 1 2 3 6. Test your function on the following numbers: 26 64, 97 and 187 Hints (a) 1 and the number itself are always factors (b) To find other factors, check up to the floor of the square root of the number. For example if the number is 10, floor 10) 3 i. 10 mod 2 equals 0. That means 2 and 5 (which is 10/2) are factors. In this case, it is OK to dynamically grow your array. ii. 100 mod 3 equals 1 which means 3 is not a factor. Since we check up to 3, this completes the function and we return 1 10 2 5 as the factors of 10 (order is not important) 2. Polynomial Evaluation (30 points This function called polyeval takes as parameters a polynomial representation as an array and a number to evaluate. For example, if the first parameter passed is -4 0 13 6, it represents 13 2 6rs. For the second parameter, if 3 is passed, then a for loop can be used to calculate the value as follows: -4 30 0 31 13 32 6 33. The function returns the result of the evaluation 3. Congruence (30 points Implement a function called Congruent which returns True if b( (mod m)) a, E meaning a is congruent to b (mod m) else it returns False. The condition for it to be true is when a (mod m) b (mod m) The funtion takes only 3 input parameters a,b and m. The function should ensure that m is a positive integer. Give two test examples that returns True and two that returns False.

Solution

%Answering only 1 question as multiple questions are asked

function d = FactorsOfNumber(x)

y = floor(sqrt(x));
j = 1;
d(j) = 1;
j = j+1;
for i=2:y
if (mod(x,i) == 0)
d(j) = i;
j = j+1;
d(j) = x /i;
j=j+1;
end
end
d(j) = x;
end

>> FactorsOfNumber(6)

ans =

1 2 3 6

Please use MATLAB to solve the following problems. Be sure to include well detailed comments so that I can understand all functions and processes. Be sure to an

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site