Question: Matlab %*************************************************************************************** %It is recommended that you debug this program offline and submit only once you have corrected the errors %*************************************************************************************** %% %These 3 loops
Matlab
%*************************************************************************************** %It is recommended that you debug this program offline and submit only once you have corrected the errors %*************************************************************************************** %%
%These 3 loops all calculate the sum of the integers from 1 through 1000
for number = 1:1000 total = total + number; end fprintf('The sum of the numbers from 1 through 1000 is %i ', total);
k=0; theTotal = 0; while k
fprintf('The sum of the numbers from 1 through 1000 is %i ', theTotal);
theTotal_2 = 0; while k >1000 theTotal_2 = theTotal_2 + k; k = k-1; end
fprintf('The sum of the numbers from 1 through 1000 is %i ', theTotal); %% %These structures all do the same thing - find the roots of a quadratic, %and print out the real roots, if any
a = 1; b = 3; c = 2;
discriminant = b^2 - 4ac;
if discriminant > 0 root1 = (-b+sqrt(b^2 - 4*a*c))/(2*a); root2 = (-b-sqrt(b^2 - 4*a*c))/(2*a); fprintf('The roots are %f and %f ', root1, root2); elseif discriminant == 0 root1 = -b/(2*a); root2 = NaN; fprintf('The root is %f and %f ', root1); else fprintf('There are no real roots '); end
aa = 1; bb = -8; cc = 16;
discriminant = bb^2 - 4*aa*cc;
switch discriminant case discriminant>0 root3 = (-bb+sqrt(bb^2 - 4*aa*cc))/(2*aa); root4 = (-bb-sqrt(bb^2 - 4*aa*cc))/(2*aa); fprintf('The roots are %f and %f ', root3, root4); case discriminant == 0 root3 = -b/(2*a); root4 = NaN; fprintf('The root is %f ', root3); otherwise fprintf('There are no real roots '); end
%% %This program calculates and plots the Fibonacci numbers that are less than %100
fibonacciNumber=[1, 1];
%first time through the loop, calculating the 3rd Fibonacci number index = 3; while fibonacciNumber
try assert(sum(fibonacciNumber>=100)==0) %The following lines will only be executed if the assertion passes fprintf('There are %i Fibonacci numbers that are less than 100;', length(fibonacciNumber)); fprintf('They are: ') fprintf('%i ', fibonacciNumber); plot(1:index, fibonacciNumber)
catch disp('Incorrect set of Fibonnaci numbers.')
end
%% %This program calls the user-defined function, GPA() to calculate a %student's grade point average
Grades = 'ABACAABBDAC'; Credits = [43454453324]; Name = "Joe"; GPAValue = gradePointAverage(grades, credits); fprintf('%s''s GPA is %d ', GPAValue);
function [ gradePointAverage] = GPA(letterGrades, numCredits ) %UNTITLED3 Summary of this function goes here % Detailed explanation goes here
qualityPoints = (letterGrades=='A')*4 + (letterGrades=='B')*3 + (letterGrades=='C')*2 + (letterGrades=='D')*1;
totalPoints = sum(qualityPoints.*credits);
gradePointAverage = totalPoints/sum(credits); end

Debugging 0 solutions submitted (max: Unlimited) 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
Step by Step Solution
There are 3 Steps involved in it
To correct the MATLAB script provided Ill go through each section and fix the errors Heres an update... View full answer
Get step-by-step solutions from verified subject matter experts
