Question: Problem Summary This is a repeat of an earlier problem. This time, you will use a while loop instead of a for loop to create

 Problem Summary This is a repeat of an earlier problem. Thistime, you will use a while loop instead of a for loop

Problem Summary This is a repeat of an earlier problem. This time, you will use a while loop instead of a for loop to create the array In mathematics, the harmonic series is the divergent infinite series: Write a MATLAB function M-file, HarmArraywhile, to 1. Input a positive integer, last 2. Use a while loop to create & return as output an array x , that contains the harmonic sequence 3. Preallocate the x array 4. Do not allow input to be an array. 5. Do not allow input to be a a non-positive integer Example if last 5, then x would be [1, 1/2, 1/3, 1/4, 1/5 >>HarmArraywhile(5) ans1.0000 .5000 0.3333 0.2500 0.2000 Test 4 (Pretest) Did not have error check for illegal integers Test Code: 1%Test array input & last >1 & integer 2 errtest-0 3 try 4 HarmArrayWhile([1 2]); 5 catch err if isempty (err. identifier) errtest=errt est %not a MATLAB-generated error statement 7 1; end 9 end 10 assert (errt est-=1, 'Did not have error check for array input') 12 errtest-0; 13 try 14 HarmArraywhile(0); 15 catch err 16 if isempty (err . identifier) %not a MATLAB-generated error statement 17 18 19 end 20 try 21 22 catch err 23 24 25 26 end 27 assert (errt est-=2,"Did not have error check for illegal integers') 28 29 errtest=0; 30 try 31 32 catch err errtest-errtest + 1; end HarmArrayWhile(-5); if isempty(err. identifier) %not a MATLAB-generated error statement errtest errtest + 1; end HarmArrayWhile(2.5); if isempty (err, identifier) errtest-errtest 1; %not a MATLAB-generated error statement 34 35 end

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!