It a second order polynomial is written in the general form ax^2 + bx + c = 0 th
ID: 3792377 • Letter: I
Question
Explanation / Answer
the m file used to do this is fairly simple consisting of -
function x = calc(a,b,c)
x(1) = (-b + sqrt(b^2 - 4 * a * c))/(2*a);
x(2) = (-b - sqrt(b^2 - 4 * a * c))/(2*a);
--
here, when we call calc we give the parameteres a,b,c. we get roots in x as x[0] and x[1],then to satisfy the condition in the question we do -
NOTE - use isreal(x) function to check if array is real or not. it will return 1 if array is REAL and 0 if it is complex. based on this we assign the "value".
if isreal(x) != true
value = 0
elseif x[0] == x[1]
value = 1
else
value = 2
----------
2)
we have already computed the roots in array "x"
to sort the values in ascending order and assign them to a vector use sortrows(x)
x_solution = sortrows(x)
NOTE - put the condition x_solution = sortrows(x) in the above if else block, to make sure we are not using it for complex roots
-------------------------
thank you
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.