Answers to questions asked in the homework if any if

This preview shows page 11 - 15 out of 15 pages.

Answers to question(s) asked in the homework (if any) (If any) Image Output Copy and paste images here
Week 5 Homework ENGR 112 Fzero while Problem 5 Extra Credit: Watch the video at this link: /watch? v=d8TRcZklX_Q&t=22s . Then download the Matlab file Kaprekars_operation.m from Homework 5. Test this file with a few random four digit numbers. Note that this script won’t work for values less than 1000. a. Change this file to be a function file that would receive one input of four digits number and would output two values - Output 1: the number the operation reaches (should be Kaprekar’s constant); Output 2: the number of iterations it took to reach that number. You do not need to submit the function file, but you will need it for your own reference in part b. b. Write a script that tests the Kaprekar’s theory for initial values between 1000 and 9998 except for the values 1111, 2222, 3333, …., 8888. Your script should print the following: i. Count of how many initial values were tested. ii. Count of how many values returned Kaprekar’s number 6174. iii. How many of these values took 1 iteration to reach Kaprekar’s number, along with how many took 2 iterations, 3 iterations, 4 iterations, 5 iterations, 6 iterations, 7 iterations, and more than 8 iterations. Self-check: for (ii), all values should return 6174. For (iii), all values should take less than 8 iterations. Comments for grader/additional information (if any) Script File % Copy and paste your script here. Must be size 10, same as MATLAB font and color. %Rick Rodey , 2.10.20, HW 5, Problem 5 extra credit, Kaprekars number %This script uses a function file made from the given matlab script %and then uses that function to test a large number of value for kaprekars %theory clear; clc; %Create an array of values between 1000 and 9998 except 1111,2222,etc %test the values with kaperkar function
Week 5 Homework ENGR 112 Fzero while numbers = 1000:9998; numbers([112,1223,2334,3445,4556,5667,6778,7889]) = []; %define the initial valuez for the function loop InitialTestVal = 0; % Initial test values InitialReturnVal = 0; % Initial values returned to kap number InitialIterationVal = zeros(1, 8); % Initial values for iteration %make a for loop that calls the function and then use if statements to %filter when it reaches kap number and to sort iteration counting for i = 1:length(numbers) [value, OperationNumber] = KapNumFunc(numbers(i)); % used kapnumfunc to do theory InitialTestVal = InitialTestVal+1; % update test values if value == 6174 %if for when the value reaches kap number InitialReturnVal = InitialReturnVal + 1; % Update values that hit kap number if OperationNumber > 8 % if statement to manage iterations OperationNumber = 8; end if OperationNumber == 0 %if statement prevent count of kap number sense i'd be 0 iterations continue ; end InitialIterationVal(OperationNumber) = InitialIterationVal(OperationNumber) + 1; % iteration count end end % Print the Results %print the count of testes value
Week 5 Homework ENGR 112 Fzero while %the count of values returned to kap number %the amount of values for each iteration fprintf( "The amount of values tested was: %0.0f\n" , InitialTestVal); fprintf(

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture