Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please solve this using SCALA Polynomials 0.0 A quadratic polynomial (i.e. a polynomial of the form ax + bx + c) can be represented as
Please solve this using SCALA
Polynomials 0.0 A quadratic polynomial (i.e. a polynomial of the form ax + bx + c) can be represented as a 3-tuple in Scala. For example: 3x2 + 9x - 30 = (3x - 6) (x + 5) = (3.0, 9.0, -30.0) Complete the implementation of poly.scala and test it with PolyTest.scala. Here is the expected output: eval(6, p) 132.0 eval (2, p) eval(-5, p = 0.0 roots (p) Some ( (2.0,-5.0)) deriv (p) (0.0, 6.0,9.0) deriv2 (p) (0.0,0.0, 6.0) Notes We can represent a polynomial of the form bx+c as the triple (0, b, c) How would you represent complex numbers in Scala? What functions would you put in complex.scala? How would you alter poly.scala to work with complex numbers? . . object poly { def roots(p: (Double, Double, Double)): Option[(Double, Double)] // - None if p has no real roots // - Some ((ri, r2)) where p(rl) -- pir2) -- 0 } def deriv(p: (Double, Double, Double)): (Double, Double, Double) // - derivative of p (which should be degree 1 def eval(a: Double, p: (Double, Double, Double)): Double // -pa) } object PolyTest extends App{ val p = (3.0, 9.0, -30.0) // - (3x (3x - 6) * (x + 5) println("eval(6, p) + poly.eval(6, p)) println("eval(2, p) + poly.eval(2, p)) println("eval(-5, p) -" + poly.eval(-5, P)) println("roots(p) + poly.roots(p)) println("deriv(p) println("deriv2 (p) + poly.deriv(p)) + poly.deriv(poly.deriv(p))) } Polynomials 0.0 A quadratic polynomial (i.e. a polynomial of the form ax + bx + c) can be represented as a 3-tuple in Scala. For example: 3x2 + 9x - 30 = (3x - 6) (x + 5) = (3.0, 9.0, -30.0) Complete the implementation of poly.scala and test it with PolyTest.scala. Here is the expected output: eval(6, p) 132.0 eval (2, p) eval(-5, p = 0.0 roots (p) Some ( (2.0,-5.0)) deriv (p) (0.0, 6.0,9.0) deriv2 (p) (0.0,0.0, 6.0) Notes We can represent a polynomial of the form bx+c as the triple (0, b, c) How would you represent complex numbers in Scala? What functions would you put in complex.scala? How would you alter poly.scala to work with complex numbers? . . object poly { def roots(p: (Double, Double, Double)): Option[(Double, Double)] // - None if p has no real roots // - Some ((ri, r2)) where p(rl) -- pir2) -- 0 } def deriv(p: (Double, Double, Double)): (Double, Double, Double) // - derivative of p (which should be degree 1 def eval(a: Double, p: (Double, Double, Double)): Double // -pa) } object PolyTest extends App{ val p = (3.0, 9.0, -30.0) // - (3x (3x - 6) * (x + 5) println("eval(6, p) + poly.eval(6, p)) println("eval(2, p) + poly.eval(2, p)) println("eval(-5, p) -" + poly.eval(-5, P)) println("roots(p) + poly.roots(p)) println("deriv(p) println("deriv2 (p) + poly.deriv(p)) + poly.deriv(poly.deriv(p))) }Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started