Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

It a second order polynomial is written in the general form ax^2 + bx + c = 0 th

ID: 3792377 • Letter: I

Question


It a second order polynomial is written in the general form ax^2 + bx + c = 0 then the roots (i.e the values of x that satisfy the equation) can be determined using the quadratic formula: x = -b plusminus Squareroot b^2 - 4ac/2a the test suite workspace includes a vector variable abc that is a 3 element row vector with values for a, b, and c in the first, second, and third column respectively. Write a script m file to do the following: Check if the roots are real and distinct. Note that the roots will be real if the value under the squareroot is greater than or equal to zero. They will not be distinct, however, if the value under the squareroot is exactly equal to zero, Create an integer variable Root condition and assign it a value as follows: the value 2 if the roots are real and distinct The value 1 if the two roots are the same The value 0 if the roots are not real complex because the value under the squareroot is less than o) in cases where there are two real and distinct roots compute the two roots and assign them in ascending order to a two element row vector x_ solution. In cases where the two roots are the same, solve for the root and assign to a scalar variable x_ solution. Do not create the variable x _solution if the roots are complex.

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

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote