I\'m a bit stuck. I\'m trying to create a polynomial evaluator using arrays. So
ID: 3528535 • Letter: I
Question
I'm a bit stuck. I'm trying to create a polynomial evaluator using arrays. So far, this is what i've done so far with my project. It's a simple program to evaluate polynomials, but now i have to use array's to make it more user adjustable.
import java.util.*;
public class PolyThree1
{
public static void main (String[] args)
{
Scanner in = new Scanner(System.in); //Scanner for user input
double a,b,c,d,e,f,x,y ; //Variables
String answer = "yes";
String answer2 = "yes";
while (answer2.equals("yes")){
System.out.println ("Enter Coefficient 5: "); // Ask's user for input
a = in.nextDouble();
System.out.println ("Enter Coefficient 4: ");
b = in.nextDouble();
System.out.println ("Enter Coefficient 3: ");
c = in.nextDouble();
System.out.println ("Enter Coefficient 2: ");
d = in.nextDouble();
System.out.println ("Enter Coefficient 1: ");
e = in.nextDouble();
System.out.println ("Enter Coefficient 0: "); // Ask's user for input
f = in.nextDouble();
answer = "yes"; //
while (answer.equals("yes")){
System.out.println ("Please enter x: ");
x = in.nextDouble();
y = c*x*x*x + d*x*x + e*x + f ;
System.out.println ("The answer is: " + y);
System.out.println ("Evaluate another x?: ");
answer = in.next();
}
System.out.println ("Another Polynomial?");
answer2 = in.next();
System.out.println ("Thanks, End of Program.");
}
}
}
I need help inserting arrays and making the java program looks more like this:
> java GenPoly
Polynomial Evaluator Release: 4.1
Enter degree of polynomial: 3 (note: new input)
Enter coefficient 3: 1 (note: don
Explanation / Answer
function horner(array, x_scale, y_scale) { function recur(x, i, array) { if (i == 0) { return array[0]; } else { return array[i] + x*recur(x, --i, array); } } return function(x) { return recur(x*x_scale, array.length-1, array)*y_scale; }; } // initialize array function zeros(n) { var array = new Array(n); for (var i=n; i--;) { array[i] = 0; } return array; } function denominator(i, points) { var result = 1; var x_i = points[i].x; for (var j=points.length; j--;) { if (i != j) { result *= x_i - points[j].x; } } console.log(result); return result; } // calculate coefficients for Li polynomial function interpolation_polynomial(i, points) { var coefficients = zeros(points.length); // alert("Denominator " + i + ": " + denominator(i,points)); coefficients[0] = 1/denominator(i,points); console.log(coefficients[0]); //new Array(points.length); /*for (var s=points.length; s--;) { coefficients[s] = 1/denominator(i,points); }*/ var new_coefficients; for (var k = 0; kRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.