Cubic Root and Cubic Equation Solver
1 Quiz 3 In Fluid properties, you learned about performing Flash calculations to find the compositions of hydrocarbon mixtures. In commercial Flash calculation packages, one problem that has to be solved repeatedly is to find the roots of a cubic equation; i.e., the values of z that make the cubic equation equal to zero, or z 3 + az 2 + bz + c = 0. (1) (Usually, we are most interested in the maximum and minimum roots because they usually correspond to the z-factors of the gas and liquid phases respectively.) Today we will write a function that will return the real roots of a cubic equation like Eq. 1. 1 To compute the cube root of a number, x 3 , we could write ” x **(1/3) ” . This would work fine as long as x is positive, but if x ≤ 0 it might give strange answers (Try it with -27). However, the cube root of a negative number exists; its value is the negative of the cube root of the absolute value of the number; i.e., for x < 0 1 1 x 3 = − |x| 3 (2) Write a function to compute the cube root of any number, positive, zero or negative. (You will use this function to evaluate all cube roots below.) (Test: cube root of -27 is -3) Now to get to the (three) roots of the cubic equation, (z1 , z2 , z3 ); first compute the following variables a2 (3) q =b− 3 r= 2a3 ab − +c 27 3 (4) q3 r2 + 27 4 (5) d= We have three cases to consider 1. |d| 10−14 : the equation only has one real root (and two complex roots). The real root is a z1 = s1 + s2 − (8) 3 where r √ 13 s1 = − + d (9) 2 and r √ 13 (10) s2 = − − d 2 Set the second and third roots equal to None. (You can test if a variable is None by “if x is None:” or if it is a value “if x is not None:” 3. d < −10−14 : the equation has three real distinct roots. They are computed as follows. Let r 3r −3 θ = arccos (11) 2q q then r −q θ a cos z1 = 2 − 3 3 3 r 2π + θ a −q z2 = 2 cos − 3 3 3 r 4π + θ −q a z3 = 2 cos − 3 3 3 (12) (13) (14) Write a function that takes a, b, and c and returns all real roots root of the cubic equation. Tests: a = -11, b = 35, c = -25 : (1, 5, 5) or (1, 1, 5) Tests: a =0.5, b = 1, c = 0.5 : (-0.5, None, None) Tests: a =-4, b = -37, c = 40 : (8, -5, 1) 2
Collepals.com Plagiarism Free Papers
Are you looking for custom essay writing service or even dissertation writing services? Just request for our write my paper service, and we'll match you with the best essay writer in your subject! With an exceptional team of professional academic experts in a wide range of subjects, we can guarantee you an unrivaled quality of custom-written papers.
Get ZERO PLAGIARISM, HUMAN WRITTEN ESSAYS
Why Hire Collepals.com writers to do your paper?
Quality- We are experienced and have access to ample research materials.
We write plagiarism Free Content
Confidential- We never share or sell your personal information to third parties.
Support-Chat with us today! We are always waiting to answer all your questions.
