Question: ENGR 1 2 0 4 Programming Languages in EngineeringLab 1 2 Python Implementation of MATLAB Lab 2 Note: For all labs and assignments copy and

ENGR 1204 Programming Languages in EngineeringLab 12 Python Implementation of MATLAB Lab 2 Note: For all labs and assignments copy and paste into a Word file your program (script file), the relevant command window and plots if applicable. Try to condense the print-out as best as possible. Convert the MATLAB program on the reverse side to a PYTHON program (.py script file) to use the quadratic formula to solve for the roots of the equation a x 2+ b x + c =0 Recall there are three cases, depending on the value of the discriminant disc = b 24 a c Set up your program to allow you to enter numerical values for the coefficients a, b and c.Use nested if-else selection statements to display one of the three messages below, followed by the solution for the roots: Two real roots exist. Double equal root exists. Two complex conjugate roots exist. Note that if the roots are complex, PYTHON will automatically display them in complex form (using j , the unit imaginary quantity equivalent to i ). A sample output is shown below: Enter a: 2Enter b: 5Enter c: 4Two complex conjugate roots exist.x1=-1.2500+0.6614 j, and x2=-1.2500-0.6614 j Run your program for the three cases shown:(1) a =1, b =4, c =2(2) a =1, b =4, c =4(3) a =1, b =4, c =8% Lab 2 MATLAB Solution to Quadratic Equation a x2+bx + c =0% Enter quadratic equation coefficients.a = input('Enter a: ');b = input('Enter b: ');c = input('Enter c: '); % Determine nature of the roots.disc = b ^2-4* a *c;if (disc >0) disp('Two real roots exist.')elseif (disc <0) disp('Two complex conjugate roots exist.')else disp('Double real root exists.')end % Calculate and display the roots.disp('The roots are: ')x1=(- b + sqrt(disc))/(2* a)x2=(- b - sqrt(disc))/(2* a) Note: For Python, to display the roots as shown in the sample output, remove the line disp(The roots are: ). Then, calculate x1 and x2, and display the results by adding the statement below: print(' x1={: .4f}, and x2={: .4f}'.format(x1, x2))

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!