Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Starter Code: import java.util.Scanner; public class CubicZeroFinder { public static void main(String[] args) { Scanner sc = new Scanner(System.in); // Read in a, b, c,

image text in transcribed

image text in transcribed

Starter Code:

import java.util.Scanner;

public class CubicZeroFinder { public static void main(String[] args) { Scanner sc = new Scanner(System.in); // Read in a, b, c, and d for our // equation ax^3 + bx^2 + cx + d = 0 int a = Integer.parseInt(sc.nextLine()); int b = Integer.parseInt(sc.nextLine()); int c = Integer.parseInt(sc.nextLine()); int d = Integer.parseInt(sc.nextLine()); // Find the zeroes String[] zeroes = findZeroes(a, b, c, d); // Print the zeroes, one per line for (int i = 0; i

Code in Java, try to place comments, post full code with starter code

(30 points) In this problem, we will use divide-and-conquer to write a pro- gram that computes the zeros of a given cubic equation. While a cubic formula exists, it is a proven fact that there is no formula that can solve every polynomial of degree 5, for example, and so it is important to con- sider numerical solutions like the one we will explore here that generalize to higher-degree polynomials. You may assume that the zeroes of these equations lie between -100 and 100 and that distinct ze- roes differ by at least 0.01. Your program should take as input four numbers, each on their own line, representing a, b, c, d (in that order) in the equation az? + bz2 + cz d = 0 For example, if our file input.txt is 7 then our goal is to solve the equation 5r3+2+7a +3-0. You may assume that a 0 The output of your program should be the three solutions of your equa- tion, each on their own line. Each solution must be rounded to five decimal places and ordered in increasing order by real part and then by imaginary part. For example, if we are solving the equation 5x3 +x2 + 7x 3 = 0 as above, your output should be 0.40464 0.10232-1.21340i 0.10232+1.21340i If your solution has a multiple root, you must print your answer that many times. For example, if your program is given the equation3 0, you must print three lines, each with the string 0.00000. As another example, if your program s given the equation x3-4x2 + 4x = 0, which can also be written as x(x - 2)2-0, your output should be the following: 0.00000 2.00000 2.00000 The class CubiczeroFinder provides starter code for reading and print- ing; your task is to fill in the findZeroes ) method Restrictions: (a) You may not use any functions in the Math library, and you may not write any additional import statements beyond those in the starter code or upload external libraries to Vocareum (b) You may not use the cubic formula (i.e. the cubic analog of the quadratic formula), nor may you use any approach that is mathemat- ically equivalent to hardcoding the cubic formula. (Most solutions that you might find on the Internet fall into this category.) However, you may wish to have a helper function that represents the quadratic formula (see below). You may also wish to use the nth root finder

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Database Upgrade Migration And Transformation Tips And Techniques

Authors: Edward Whalen ,Jim Czuprynski

1st Edition

0071846050, 978-0071846059

More Books

Students also viewed these Databases questions

Question

Explain the causes of indiscipline.

Answered: 1 week ago