Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

New to MATLAB?

Problem 1954. Write a cubic formula function

Created by Tyler

Create a function that will output the three roots of a cubic equation specified by the 4 coefficients listed as input. The output should be sorted using the "sort" function of matlab, to be consistent. Also, the output need only be accurate to the 4th decimal place, and the input "A" will always be non-zero and real.


A*x^3+B*x^2+C*x+D=0 --> [A,B,C,D]

x^3-6x^2+11x-6=0 --> [1,-6,11,-6]

cubicFormula([1,-6,11,-6]) --> [1,2,3]

Problem Group

Solution Statistics

14 correct solutions 69 incorrect solutions
Last solution submitted on Apr 27, 2015

Problem Comments