Question
(a) Using MATLAB, create a function which takes a number parameter as an input, and outputs that number and all the numbers below it in
(a) Using MATLAB, create a function which takes a number parameter as an input, and outputs that number and all the numbers below it in an array in all different orders possible.
Example: input 3 into the function, and outputs 3!=6 arrays with each array having different orders of 1,2, and 3 displayed. This should result in arrays [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], and [3,2,1]. If the input is 5, then there should be 5!=120 arrays.
(b) Create a function that goes through all of the arrays in part a, takes a parameter s, with s representing the amount of array entries to be skipped and have the function output an array called 'result' that outputs the lowest number or last index value from the list of arrays in part a.
Example: if the number 5 was used as an input in part a, then there should be 5!=120 arrays. Let the, let's say, 7th array be: [1,3,2,5,4]. Then input 2 into the function (skipping 2 entries, in this case 1 and 3), and output a number lower than the lowest number in the entries skipped, otherwise output the last entry, which is 4. Then the number 4 should be placed in the 7th index of the 'results' array. Let's say the 78th array was [3,4,1,2,5], input 2 into the function (skipping 2 entries, in this case 3 and 4), the function should output 1 and be placed into the 78th index of the 'results' array.
(c) Create a function that goes through the 'results' array from part b, and have a variable called 'success' (whose initial value is 0) and have its value increase by 1 each time the function detects the number 1 in the indexes of the array. Example: Let the 'results' array have 120 indexes. If 58 of those indexes have the value of 1, the 'success' variable should equal 58. Have the function output a variable called final, which equals '(success/ total # of indexes in the array) * 100'.
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