ENGR 1181 | MATLAB 8: Conditional StatementsMAT_08D_Conditional_Statements_Assignment

Follow the format that you’ve been doing for previous problems.

·  Do the entire problem in one script file.

·  Your script file should include comment statements to help organize your script file.

·  Make sure the Command Window displays your name, the assignment name, and your group number.

·  Submit based on your instructor’s guidelines.

Define – Problem Statement

The “Define” step is completed for you.

You will be writing a program that determines the real roots of a quadratic equation

ax2+bx+c=0.

The algorithm:

1.  Ask the user to enter the values of the constants a,b, and c. The quadratic equation can be solved using the quadratic formula.

2.  The quadratic formula is a combination of calculations which gives, at most, two real roots:

Root1 = x=-b+b2-4ac2a or x=-b+D2a

Root2 = x=-b-b2-4ac2a or x=-b-D2a

Where D = b2-4ac

3.  Calculate D.

4.  Calculate the real roots.

a.  If D < 0, tell the user “The equation has no real roots”.

b.  If D=0, tell the user “The equation has one real root” and display the root.

c.  If D>0, tell the user “The equation has two real roots” and display the roots.

5.  Calculate the values of the real roots.

Instructions – Part 1

Represent

·  On a sheet of paper, draw a flowchart for the algorithm above. See the course website for flow chart symbols (found on MATLAB 1 – Program Design).

Plan

·  In a MATLAB script file, using only detailed comment statements, outline what you will do to write the above program. As always, make sure to include your name, the assignment name, and your group letter.

·  Print out and turn in a hard copy of your flowchart (make sure your name and table number are listed).

·  Print a PDF of your script file (commented outline of your code) and submit to Carmen Dropbox.

·  Continue with Part 2

Instructions – Part 2

Implement

·  Build on Part 1 and write the script file to determine the real roots of a quadratic equation. The script file needs to tell the user how many real roots there are for the quadratic equation and the values of the real roots. Use fprintf to display this information to the user.

Run the code three times for the following three equations:

a.  -3x2+7x+5=0

b.  3x2+6x+3=0

c.  -3x2+4x-6=0

Evaluate

·  On a sheet of paper, solve the above three equations by hand and show your work. Verify that your answers match the answers provided by MATLAB.

Document

·  Print a PDF of your script file and the command window output. Turn in a hard copy or submit to Carmen Dropbox based on your instructor’s guidelines. Turn in a hard copy of your hand calculations.