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

Write a function function [xl, x2, flag] = quad(a, b, c) which computes the root

ID: 3080249 • Letter: W

Question

Write a function function [xl, x2, flag] = quad(a, b, c) which computes the roots of the quadratic equation ax2 + bx + c = 0. The input arguments a, b and c (which may take any values) are the coefficients of the quadratic, and xl, x2 are the two roots (if they exist), which may be equal. See Figure 3.3 in Chapter 3 for the structure plan. The output argument flag must return the following values, according to the number and type of roots: 0: no solution (a = b = 0, c 0); 1: one real root (a = 0, b 0, so the root is -c/5); 2: two real or complex roots (which could be equal if they are real); 99: any x is a solution (a = b = c = 0).

Explanation / Answer

function [x1,x2,flag] = quad(a,b,c) if (a==0 && b==0 && c==0) flag = 99; if (a==0 && b==0) flag = 0; else if (a==0) x1= -c/b; flag = 1; else x1= [-b+sqrt(b^2 - 4*a*c) ]/(2*a) ; x2 = [-b-sqrt(b^2 - 4*a*c) ]/(2*a) ; flag = 2;

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote