Let us solve a second order algebraic equation ar2 + bx+c = 0. The solution is g
ID: 2292755 • Letter: L
Question
Let us solve a second order algebraic equation ar2 + bx+c = 0. The solution is given in analytical form as x== - -h+ Vb2 - 4 * a*C 2 *a If the argument of the radical, i.e. b2 – 4 % a*c is negative the two roots are complex conjugates, if b) – 4 *a*c is zero the two roots are repeated, and if b2 – 4 **a*c is postive then the two roots are real. Write a function named (r1,r2,msg ] = sec_root(a,b,c) The argument = b2 - 4ac is used to determine the roots.... if the argument is negative return the roots n = -b+jv-argument) and re= (-b-jV-argument) and a message string 'The roots are complex D conjugates' if the argument equals zero return n1 = and a message string 'The roots are repeated' otherwise, r = Sar - (- + vargument) andre - (-b+ vargument) 2 and a message string The roots are real'Explanation / Answer
function [r1,r2,msg]=sec_roots(a,b,c)
for k=1:3
%let argument be d=b^2-4ac
a=input('enter a: ');
b=input('enter b: ');
c=input('enter c: ');
d=b^2-4*a*c
if d<0
fprintf(' the roots are complex conjugates. ')
r1=(-b+(sqrt(-d))*i)/(2*a)
r2=(-b-(sqrt(-d))*i)/(2*a)
fprintf(' %0.3f and %0.3f ',r1,r2)
elseif d==0
fprintf(' the roots are repeated. ')
r1=(-b)/(2*a)
r2=(-b)/(2*a)
fprintf(' %0.3f and %0.3f ',r1,r2)
elseif d>0
fprintf(' the roots are real. ')
r1=(-b+(sqrt(d))*i)/(2*a)
r2=(-b-(sqrt(d))*i)/(2*a)
fprintf(' %0.3f and %0.3f ',r1,r2)
end
end
end
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.