Problem 1954. Write a cubic formula function
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.
Example:
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]
Solution Stats
Problem Comments
-
3 Comments
the "sorted" requirement is problematic, I would suggest you drop this requirement and simply resort the output of cubicFormula after (not before) rounding to four digits (and apply the same logic to your testsuite)...
is there maybe a several problem with the sorting method you describe/need?? :-/
The problem requires abs as 'ComparisonMethod' for sorting and the non-conjugate transpose. That's a pain that I have just become aware: ' is the conjugate transpose, and .' is the non-conjugate transpose. The conjugate operator changes the signs of complex roots.
Solution Comments
Show commentsProblem Recent Solvers19
Suggested Problems
-
Get the area codes from a list of phone numbers
1064 Solvers
-
Determine if a Given Number is a Triangle Number
383 Solvers
-
1565 Solvers
-
Getting the row and column location from a matrix
289 Solvers
-
Cell Counting: How Many Draws?
2147 Solvers
More from this Author1
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!