Skip to content

Commit

Permalink
Create quadraticSolver.m
Browse files Browse the repository at this point in the history
  • Loading branch information
mcafaro committed Feb 5, 2024
1 parent a779c01 commit 05a77b3
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions subfolder/quadraticSolver.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function roots = quadraticSolver(a,b,c)
% quadraticSolver returns solutions to the
% quadratic equation a*x^2 + b*x + c = 0.

if ~isa(a,'numeric') || ~isa(b,'numeric') || ~isa(c,'numeric')
error('quadraticSolver:InputMustBeNumeric', ...
'Coefficients must be numeric.');
end

roots(1) = (-b + sqrt(b^2 - 4*a*c)) / (2*a);
roots(2) = (-b - sqrt(b^2 - 4*a*c)) / (2*a);

end

0 comments on commit 05a77b3

Please sign in to comment.