Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Quadratic Solver ( if - elseif - else ) If a second order polynomial is written in the general form: a x 2 + b

Quadratic Solver (if-elseif-else)
If a second order polynomial is written in the general form:
ax2+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+-b2-4ac22a
Code has already been provided to define a function named quadraticSolver that accepts a 3-element row vector and assigns it to the input variable abc, with values for a,b,
and c in the first, second, and third column respectively. Add commands to do the following:
Check if the roots of the polynomial defined by a,b, and c are real and distinct. Note that the roots will be real if the value under the square root is greater than or equal to
zero. They will not be distinct, however, if the value under the square root is exactly equal to zero. Assign an an integer (uint8 datatype) value to the output variable
rootCondition 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 (i.e. complex because the value under the square root is less than 0)
Assign the solution to the quadratic to the output variable rootValues according to the following guidelines:
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.
In cases where the two roots are the same, compute the root and assign this value to both elements in a two-element row vector.
In cases where the roots are complex, output assign the text 'complex roots' output variable rootvalues.
Note the value of abc is defined as a function input. Do not overwrite this value in your code. Be sure to assign values to each of the function output variables.
Use an if-elseif-else structure in your code.
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Access Patterns Database Interactions In Object Oriented Applications

Authors: Clifton Nock

1st Edition

0321555627, 978-0321555625

More Books

Students also viewed these Databases questions

Question

What does Processing of an OLAP Cube accomplish?

Answered: 1 week ago