Lecture18 The If Statement


Read Gilat 6.2
Work these problems:
1.    Write a script which does the following:
a.    Obtain integers a, b, and c between -5 and +5 (use randi([-5, 5]) to create a radom number), which represent coefficients of a 2nd order polynomial, a, b, c
b.    Print the coefficients as shown below using fprintf.
c.    Compute the discriminant of the quadratic formula,  d = b^2-4ac
d.    Depending on whether a is zero or non-zero, and whether the discriminant is positive, zero, or negative, compute the roots if they exist and print one of the solution lines below using fprintf.
Coefficients a, b, c = xx, xx, xx
There is no solution because a=0
The solution has 2 real roots: x.xxx, x.xxx
The solution has 1 root: x.xxx
The solution has no real roots

Your solution will use some combination of if / elseif / else.  Run your program multiple times until you see all logic paths exercised.

2.    Write a script which does the following:
a.    In a temperature measurement, [24 22 20 22 999 25 25 999], there are bad reading values, which are represented by ‘999’.
b.    Test the vector for the existence of any bad values.  If there are no bad values do nothing.
c.    If there are bad values do the following:
i.    Modify the vector to omit the bad values
ii.    Print the following message and the corrected vector:
    *** xx bad values detected and removed
    [new vector]

You should use fprintf to print the first message.  You can use disp to print the new vector.

ANSI C conversion specification includes these conversion characters.

Send your work to the email by Wednesday.