Starting from:

$25

COMPSCI1JC3-Assignment 1 Haskell-Cubic Calculator Solved

The purpose of Assignment 1 is to write a program in Haskell that computes the solutions of a cubic equation.

1      Background
Recall from high school mathematics that a quadratic equation

ax2 + bx + c = 0,

where a,b,c are real numbers with a 6= 0, has two solutions:

 .

The solutions of the quadratic equation depend on the value of b2 − 4ac called the discriminant of the equation. If b2 − 4ac < 0, the two solutions are non-real complex numbers; if b2 − 4ac = 0, the two solutions are real numbers equal to each other; and if b2 − 4ac 0, the two solutions are distinct real numbers.

Less well known is that a cubic equation

ax3 + bx2 + cx + d = 0,

where a,b,c,d are real numbers with a 6= 0, has three solutions:

 

where:

 .

The derivation of the solutions x1, x2, and x3 is elegantly presented in the ProofWiki article “Cardano’s Formula” found at https://proofwiki.org/wiki/Cardano’s Formula.

The solutions of the cubic equation depend on the value of Q3+R2 called the discriminant of the equation as follows:

1.    If Q3 + R2 < 0, then the three solutions are distinct real numbers. However, these solutions require complex number arithmetic to compute.

2.    If Q3+R2 = 0, then the three solutions are real numbers with x2 = x3. It is possible that x1 = x2 = x3 in this case.

3.    If Q3 + R2 0, then x1 is a real solution, but x2 and x3 are two non-real complex solutions.

Historical note: The general solution for cubic equations was first devised by Niccol`o Fontana Tartaglia (1499–1557) in 1530 and first published by Gerolamo Cardano (1501–1576) in 1545. The general solution for quartic equations (of degree four) was discovered by Lodovico Ferrari (1522–1565) in 1540. Niels Henrik Abel (1802–1829) gave the first complete proof in 1824 that general solutions do not exist for equations of degree five or greater.

2       Assignment 1
The purpose of this assignment is to compute — using only real number arithmetic — approximations of the real number solutions of a cubic equation with floating point coefficients.

2.1                  
then the value of pQ[1] + R2 is not a real number. That is, these functions should return NaN — which stands for “not a number” — when Q[2] + R2 < 0.

For example, if the cubic equation is

x3− 3x = 0,

                                                                                                                    √                               √ 

then by factoring it is clear that x[3] = 0, x2 = 3, and x3 = − 3. However, Q3 + R[4] = −1, so cubicRealSolutions 1 0 (-3) 0 should return [] instead of

[0.0,1.7320508075688772,-1.7320508075688772].

It is a useful exercise to compute x1, x2, and x[5] for this equation using complex number arithmetic.

8. Your file loads successfully into GHCi and all of your functions perform correctly.



 
[1] Assignment 1 Extra Credit

The purpose of this extra credit assignment is to compute approximations of the complex solutions of a cubic equation with floating point coefficients. This is a very challenging assignment; do not be discouraged if you cannot complete it.

More products