Consider the cubic equation: f(x) = Ax^3 + Bx^2 + Cx + D. The inflections (turni
ID: 3782867 • Letter: C
Question
Consider the cubic equation: f(x) = Ax^3 + Bx^2 + Cx + D. The inflections (turning points) of the curve will occur where the derivative of f is zero. The locations of these zeros can be found by finding the roots (zeros) of the quadratic equation: g(x) = 3Ax^2 + 2Bx + C. Remember that the roots of a general quadratic equation Q(x) = ax^2 + bx + C are: x_1 = -b + Squreroot b^2 - 4ac/2a, x_2 -b-squareroot b^2 - 4ac/2a. Using the expressions above, write a MATLAB function that will take as input the coefficients A, B and C, and provide as output the locations of the turning points of f(x). Remember that there may be zero, one or two turning points, so your function will need to work intelligently for each case. Show the output of vour function for the following cases: A = 1/3 B = -500.05 C = 1 A = 1/3 B = -5000.05 C = 1 A = 1/3 B = -50 000.05 C = 1 a = 1/3 B = -500 000.05 C = 1Explanation / Answer
basically we're required to calculate the roots of a quadratic equation in matlab -
also , remember that we need to include 3A and 2B instead of the normal a and b in the eqaution .
then for that x1 and x2 calculate the f(x) with the help of the given equation -
-------------
code
-----------------
arr=input('coefficients of f(x) as a array "[A,B,C,D]":');
A=3 * arr(1); %since it is 3A
B=2 * arr(2); %sincce it is 2B
C=arr(3);
D=arr(4);
if (A==0) && (B~=0)
fprintf('There is a single root at %g. ', -C/B);
fpritf('location of f(x) at %g',B/2*(-C/B)*(-C/B) + C * (-C/B) + D );
end
if (A~=0) && (B==0)
fprintf('There are two real roots at 0 and %g. ', -B/A);
fprintf('one location of f(x) is %g. ', D);
fprintf('other location is %g. ', A/3*(-B/A)*(-B/A)*(-B/A) + C * (-B/A) + D);
end
if (A~=0) && (B~=0)
root1=((-B+sqrt(B*B-4*A*C))/(2*A));
root2=((-B-sqrt(B*B-4*A*C))/(2*A));
if isreal(root1)
fprintf('There are two real roots at %g and %g. .', root1, root2);
fprintf('first location of f(x) is %g. ',A/3*root1*root1*root1 + B/2*root1*root1 + C*root1 + D);
fprintf('first location of f(x) is %g. ',A/3*root2*root2*root2 + B/2*root2*root2 + C*root2 + D);
else
fprintf('The roots are complex: ');
fprintf(' ');
disp(root1);
fprintf(' and ');
disp(root2);
end
end
--------------------------------------
example test run
for A = 1/3 B = -5000.05 C = 1
we'll get the g(x) as x3 - 10000.01 x 2 + 1
so we'll get the roots as 10000.00900000 and 0.000099999
so f(x) will be -166749990180 and 0.000049995
-------------------
thank you
--------------