Question: Correct all errors in the provided script. Remember that some errors are fatal (result in an error message) while others simply cause the program to



Correct all errors in the provided script. Remember that some errors are fatal (result in an error message) while others simply cause the program to produce incorrect results. You can assume that you have fixed all errors when the checker passes all tests. Script Reset MATLAB Documenta 1 %********* 2 %It is recommended that you debug this program offline and submit only once you have corrected the errors 3 ***** 6 %These 3 loops all calculate the sum of the integers from 1 through 1000 8 for number = 1:1000 total = total + number; 10 end 11 fprintf('The sum of the numbers from 1 through 1000 is %i ', total); 13 k=0; theTotal = 0; while k 1000 theTotal_2 = theTotal_2 + k; k = k-1; 26 end 28 fprintf('The sum of the numbers from 1 through 1000 is %i ', theTotal); 29 %% 30 %These structures all do the same thing - find the roots of a quadratic, 31 fand print out the real roots, if any 33 a = 1; 34 b = 3; 35 C = 2; 37 discriminant = b^2 - 4ac; 40 if discriminant > 0 root1 = (-b+sqrt(6^2 - 4*a*c))/(2*a); 42 root2 = (-b-sqrt(6^2 - 4*a*c))/(2*a); fprintf("The roots are %f and %f ', rooti, root2); elseif discriminant == 0 root1 = -b/(2*a); root2 = NaN; fprintf("The root is 3f and 3f ', root1); 49 else se fprintf("There are no real roots '); 51 end 53 aa = 1; 54 bb = -8; 55 cc = 16; 57 discriminant = bb^2 - 4*aa*cc; 59 switch discriminant case discriminant> root3 = (-bb+sqrt(bb^2 - 4*aa*cc))/(2*aa); root4 = (-bb-sqrt(bb^2 - 4*aa*cc))/(2*aa); fprintf('The roots are sf and %f ', roots, root4); case discriminant == 0 root3 = -b/(2*a); root4 - NaN; fprintf('The root is % ', root3); otherwise fprintf('There are no real rootsin'); 71 end 73 36 74 %This program calculates and plots the Fibonacci numbers that are less than 75 %100 77 fibonacciNumber=[1, 1]; 79 %first time through the loop, calculating the 3rd Fibonacci number 80 index = 3; 81 while fibonacciNumber =100)==0) %The following lines will only be executed if the assertion passes fprintf('There are si Fibonacci numbers that are less than 100;', length(fibonacciNumber)); fprintf('They are: ') fprintf('%i ', fibonacciNumber); plot(1: index, fibonacciNumber) catch ME switch ME. identifier case 'MATLAB: assertion: failed disp('Incorrect set of Fibonnaci numbers.') case 'MATLAB:samelen' disp('error in plot - vectors not the same length) otherwise disp('Something is wrong with the Fibonacci number code') end end 111 %This program calls the user-defined function, GPA) to calculate a 112 %student's grade point average 114 Grades = 'ABACAABBDAC'; 115 Credits = [43454453324]; 116 Name = "Joe"; 117 GPAValue = gradePointAverage (grades, credits); 118 fprintf('%s''s GPA is %d ', GPAValue); 122 function ( gradePointAverage] = GPA(letterGrades, numcredits ) 23 %UNTITLED3 Summary of this function goes here 124 % Detailed explanation goes here 125 126 qualityPoints = (letterGrades=='A')*4 + (letterGrades=='B')*3 + (letterGrades=='C')*2 + (letterGrades=='D')*1; totalPoints = sum(qualityPoints. *credits); gradePointAverage = totalPoints/sum(credits); end
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
