Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

As every algebra student knows, the quadratic formula gives the solutions to qua

ID: 3855541 • Letter: A

Question

As every algebra student knows, the quadratic formula gives the solutions to quadratic equations of the form ax^2+bx+c=0. Not many people are aware that a formula also exists to solve cubic equations of the form x^3+ax^2+bx+c=0. This formula is called Cardano's formula, after the Italian mathematician who allegedly derived it several hundred years ago. The formula says that the solution is given by x=u-p/3u-a/3, where p=b-(a^2)/3, q=c+ (2a^3-9ab)/27, u= 3rd root of a. Using Java's built in Math.pow and Math.sqrt methods, write a method that takes parameters for the coefficients a,b and c, then returns the solution to the cubic equation. b. Within the same source code file as your solution for (a), write a main method that allows the user to enter values for a,b and c, then calls your method from (a) and displays the result. in java

Explanation / Answer

package equations;

import java.util.Scanner;

import java.lang.Math;

class CubicEquation{

public static void main(String[] args) {

                         Scanner sc=new Scanner(System.in);  

                      System.out.println("Enter value of a");  

                        double a=sc.nextDouble();  

                       System.out.println("Enter value of b");  

                        double b=sc.nextDouble();  

                        System.out.println("Enter value of c");  

                         double c=sc.nextDouble();  

                        // calling method to solve the cubic equation

                   System.out.println(new CubicEquation.SolveCubic(1.0, -3.0, 9.0)); //

//method to find solution

public double SolveCubic((double a, double b, double c){

double p = -(b)-Math.pow(a, 2)/3;

double q = c +2* (Math.pow(a, 3) -9 *a*b)/27;

double u= Math.cbrt(q + Math.sqrt(Math.pow(q, 2.0) + Math.pow((r - Math.pow(p, 2.0)), 3))) + Math.cbrt(q - Math.sqrt(Math.pow(q, 2.0) + Math.pow((r - Math.pow(p, 2.0)), 3))) + p;

double x= u-p/(3*u)-a/3;

return x;

}

}