Question
Write a function called checkFactor that takes two arrays of positive numbers, firstNumberRow and secondNumberRow. checkFactor checks if the first entry in firstNumberRow is divisible
Write a function called checkFactor that takes two arrays of positive numbers, firstNumberRow and secondNumberRow. checkFactor checks if the first entry in firstNumberRow is divisible by the first entry in secondNumberRow, and performs the same operation on the next array elements until all entries have been checked. All the numbers are positive and the number of entries in the arrays are the same. The function should return the identified divisible numbers in two row arrays named firstDivisible and secondDivisible.
Restrictions: Branches or loops should not be used. The code must use the internal mod and logical functions.
Hint: The mod function should be used to determine if two numbers are divisible. Ex: for Num1 and Num2 if mod(Num1,Num2) is 0, then the two numbers are divisible.
This is MATLAB
Ex: firstNumberRow-[5, 7, 8, 6, 31: secondNumberRow= 17, 7, 2, 3, 51: [firstDivisible,secondDivisible]-checkFactor(firstNumberRow, secondNumberRow) produces firstDivisible = secondDivisible indicating that the second entries (the two 7s), the third entries (the 8 and the 2), and finally the fourth entries (the 6 and 3) are divisible positive integers. Your Function Save Reset MATLAB Documentation function IfirstDivisible, secondDivisible]-checkFactor(firstNumberRow, secondNumberRow) % Create a logical array with true at all the entries that are divisible 5% Use logical indexing and the the array testArray to create firstDivisible 71% Use logical indexing and the the array testArray to create secondDivisible 9 end tArray- ; % complete the code 10 Code to call your function C Reset IfirstDivisible,secondDivisible]-checkFactor(firstNumberRow, secondNumberRow)Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started