In: Civil Engineering
1. Solve quadratic equation Ax^2+Bx+C=0 using the quadratic formula x = (-B+ and - sqrt(B^2-4ac)) / 2a) and output the two solution with clear explanation
could you please do it in MATLAB
clear, clc
disp ('For the equation ax^2+bx+c')
a=input ('Enter a:');
b=input ('Enter b:');
c=input ('Enter c:');
D=b^2-4*a*c;
if D<0
fprintf ('\nThe equation has no real roots. \n \n')
else
if D==0
root=-b/ (2*a)
fprintf ('\nThe equation has one root, \n')
fprintf (' %.3E \n \n ' , root)
else
r1=(-b+sqrt (D)) /(2*a);
r2=(-b-sqrt (D)) /(2*a);
fprintf ('\nThe equation has two roots, \n')
fprintf ( ' %.3f and %.3f \n \n' , r1, r2 )
end
end
if you want any modifications please comment here