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

Show MatLab code required for this question please Matlab Questions: Problem 2:

ID: 2997518 • Letter: S

Question

Show MatLab code required for this question please Matlab Questions: Problem 2: Write a function to compute and display the roots of a quadratic equation: ax^2 + bx + c = 0. The inputs for this function are the coefficients a, b, and c. If the equation does not have any real root, the function must display message: no real roots. Then, call this function in a script file to compute the roots of the following equations: 5x^2 + 6x + 1 = 0 x^2 - 10x + 34 = 0 Display the results obtained in each case.

Explanation / Answer

a = input ('Enter value for a : ');
b = input ('Enter value for b : ');
c = input ('Enter value for c : ');
x = [a b c];
R = roots(x)
tf = isreal(R);
if (tf==0)
    display('No real roots')
end

-------------------------------------------------------------------

Enter value for a : 5
Enter value for b : 6
Enter value for c : 1

R =

   -1.0000
   -0.2000

---------------------------------------------------------------


Enter value for a : 1
Enter value for b : -10
Enter value for c : 34

R =

   5.0000 + 3.0000i
   5.0000 - 3.0000i

No real roots