Write a function to find the roots of the cubic equation in matlab without using
ID: 3666207 • Letter: W
Question
Write a function to find the roots of the cubic equation in matlab without using any of the root finding functions in Matlab. Your function statement should be function [ x ] = cubicRoots( a, b, c, d ).
We are supposed to use this link to help https://en.wikipedia.org/wiki/Cubic_function#Roots_of_a_cubic_function but I don't really know what to do. Below is the example of a quadratic equation and what he would want for that:
function [ x ] = quadroots( a, b, c )
% find the real roots of the quadratic equation ax^2 + bx + c
% input parameters
% a = real coefficient of cubic equation
% b = real coefficient of cubic equation
% c = real coefficient of cubic equation
% output parameter
% x = 1 x 2 vector containing the 2 roots of the quadratic equation
D = b^2 - 4*a*c; % discriminant
if D >= 0 % real roots
x(1) = (-b - sqrt(D))/(2*a);
x(2) = (-b + sqrt(D))/(2*a);
else
x(1) = NaN;
x(2) = NaN;
end
end