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
Explanation / Answer
function [] = solve_cubic() w=10:2:30; a=4*((9*w)-7); b=(-2)*((18*w)-16).*(w+1); c=3*((w+1).^2).*((3*w)-1); d=(-3)*((1+w).^3); f = zeros(1,length(w)); for ii = 1:numel(w) g = roots([a(ii),b(ii),c(ii),d(ii)]); f(ii) = g(gRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.