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

Write a function that takes three inputs: a, b and c of the standard polynomial

ID: 3793424 • Letter: W

Question

Write a function that takes three inputs: a, b and c of the standard polynomial form ax^2 + bx + c = 0 And returns two outputs, the two solutions of the quadratic equation. You need not worry about negative numbers inside of radicals (like sqrt (-1)), as MATLAB can handle complex and imaginary numbers! a = 1; b = 6; c = 5; correct1 = -1; correct2 = -5; [x1 x2] = quadratic (a, b, c); assert ((isequal (x1, correct1)||isequal (x1, correct2))&& ((isequal (x2, correct1)||isequal (x2, correct 2))))

Explanation / Answer

function [x1,x2] = quadratic(a,b,c)
  
%First calculate determinant
d = sqrt(b^2 - 4*a*c);

%Now using determinant to find roots
x1 = (-b+d)/(2*a);
x2 = (-b-d)/(2*a);

end

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