Solving Quadratic Equations (Version 1) - MATLAB Cody - MATLAB Central

Problem 2510. Solving Quadratic Equations (Version 1)

Difficulty:Rate

Quadratic equations have the form: ax^2 + bx + c = 0. Example: x^2 + 3x + 2 = 0, where a = 1, b = 3, and c = 2. The equation has 2 real solutions (roots): x = -1 and x = -2. The quadratic formula can be used to find the roots:

The formula can be translated into the computation of two roots x1 and x2:

x1 = -b + ...
x2 = -b - ...

Complete the function to solve the quadratic equation denoted by a, b, and c. Assume the discriminant --- b^2 - 4ac --- is not negative, ensuring that x1 and x2 are real.

Solution Stats

44.45% Correct | 55.55% Incorrect
Last Solution submitted on Jun 03, 2025

Problem Comments

Solution Comments

Show comments
Why should you share code?
In a discussion on LInkedin about my recent blog post, Do these...
3
6

Problem Recent Solvers497

Suggested Problems

More from this Author6

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!