Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Can you please help with this assignment. The purpose of this assignment is to w

ID: 1862505 • Letter: C

Question

Can you please help with this assignment.


The purpose of this assignment is to write a MATLAB program to determine the roots of a 2nd order polynomial. To do this please use the input() function we discussed in our last lecture. Please use newline characters at the end of any messages printed to the user (input() or sprintf()). The program flow should consist of the following: Query the user for input with "Input the coefficient 'a' from the quadratic equation". Save this input as a. Go to step 2. If the input from the user is a single numeric non-zero real value go to step 3, otherwise go to step 1. Query the user for input with "Input the coefficient 'b' from the quadratic equation". Save this input as b. Go to step 4. If the input from the user is a single numeric real value go to step 5, otherwise go to step 3. Query the user for input with "Input the coefficient 'b' from the quadratic equation". Save this input as c. Go to step 6. If the input from the user is a single numeric real value go to step 7, otherwise go to step 5. Calculate the roots of the quadratic using the coefficients from the user. Print the resulting two roots of the quadratic to the user using sprintf(). If the roots are repeated the message to the user should be 'There is one repeated root at X + Yi" where X and Y are the real and imaginary parts of the roots, to 8 significant figures. If the roots are unique print the message "Root N is at X + Yi" where N is the number of the root (1 or 2), X is the real part of the root with 8 significant figures, and Y is the imaginary part of the root to 8 significant figures. You can use isreal(), isnumeric(), and lengthQ when testing for valid input.

Explanation / Answer

a = 0;

while(isreal(a) == 0 || a == 0)

    a = input('Input the coefficient a from the quadratic equation ');

end

b = input('Input the coefficient b from the quadratic equation ');

while(isnumeric(b) == 0)

    b = input('Input the coefficient b from the quadratic equation ');

end

c = input('Input the coefficient c from the quadratic equation ');

while(isnumeric(c) == 0)

    c = input('Input the coefficient c from the quadratic equation ');

end

p = [a b c];

r = roots(p);

if (r(1) == r(2))

    t = sprintf('There is one repeated root at %5.8f + %5.8fi ',real(r(1)),imag(r(1)));

else

    t = sprintf('Root 1 is at %5.8f + %5.8fi Root 2 is at %5.8f + %5.8fi ',real(r(1)),imag(r(1)),real(r(2)),imag(r(2)));

end

disp(t);