Write a matlab function myquad (a, b, c) that returns the roots of a quadratic e
ID: 1843760 • Letter: W
Question
Write a matlab function myquad (a, b, c) that returns the roots of a quadratic equation ax^2 + bx + c = 0. The algorithm you need to use: Test whether the equation is a true quadratic or not by checking whether a is non-zero. If a = 0, (the equation is not a true quadratic) two situations exist If b = 0, it is the case of a trivial solution Else, we have a case with a single root r_1 = -c/b If a notequalto 0 three situations exist depending on the value of the discriminant, d = b^2 - 4 a c, If d = 0, we have two equal real roots If d > 0, we have two unequal real roots If dExplanation / Answer
function myquad= Quadratic(a,b,c)
if a==0,
x= -c/b;
else
x(1) = (-b+sqrt(b^2-4*a*c))/(2*a);
x(2) = (-b-sqrt(b^2-4*a*c))/(2*a);
disp(x(1))
disp(x(2))
fprintf('x(1) = %f ',x(1));
fprintf('x(2) = %f ',x(2));
end
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.