Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a MATLAB function named isDivll to receive a number as input, and determine if it is divisible by 11. The output argument is a
Write a MATLAB function named isDivll to receive a number as input, and determine if it is divisible by 11. The output argument is a logical-1 (true) if the number is divisible by 11 and 0 (false) if it is not. Code Requirements: No division is allowed! Instead determine if the number is divisible by 11 using this rule: Take the alternating sum of the digits in the number, reading from left to right. If that is divisible by 11, so is the original number. So, for instance, 2728 has alternating sum of digits 2-7+2-8 = -11. The number 91818181818, which has an alternating sum of 44, is also divisible by 11. Additionally, if the alternating sum is zero, it is divisible by 11. No MATLAB functions that can be used to determine divisibility (such as rem) are permitted No vectorization is allowed! Do not use any functions, such as sum, any, or find, that work on an entire array. This includes use of the colon operator (except in a for loop) *****Violation of these requirements will result in a grade of zero for this part of the assignment******* Input Restrictions & special cases: The function should halt and return a red error message for the following conditions. Any input is nonscalar Any input is not a positive integer Any input is greater than or equal to 1times10^15 Write a MATLAB function DivByllList that takes an array of positive integers as input. The output argument is an array that contains the numbers from the input array that are divisible by 11. Use function isDivll to determine divisibility. Code Requirements: The function M file must use the function isDivll. No credit will be given if divisibility is determined any other way The function M-file must contain isDivll as a subfunction No vectorization is allowed, nor use of any functions, such as sum, any, or find, that work on an entire array. Input Restrictions & special cases: No extra code is required. Leave the error statements as is in isDivll The function should return an empty array if none of the elements of the input array are divisible by 11 (see example above)
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