Consider the cubic equation fx Ax3 Bx2 Cx D The inflecti
Solution
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
--------------

