Evaluate Nth Degree Polynomial For A Given Value Of X

Apr 8, 2014

To evaluate a nth degree polynomial for a given value of x using JAVA PRG.

E.g. 5x^7 + -2x^5 + 6x^3 + 1x^0 at x=2

The program must read in the number of non-zero terms in the polynomial followed by the co-efficient and power of each term. The value of x is read from the used and the program display the results of the evaluation of the polynomial. Use array list to represent the polynomial.

Test Case 1:
Input: No of terms: 4
Term n-1 to 0 (both coeffient and power )
5 7
-2 5
6 3
1 0
x = 2 (say)

Output :
625

View Replies


ADVERTISEMENT

Simplifying Polynomial From Divided Difference Table

Nov 25, 2014

I am writing a method that simplify polynomial from something like this:

3 + 1/2(x-1) +1/3(x-1)(x-3/2) - 2(x-1)(x-3/2)x
to:
-2x^3 + 5.334x^2 - 3.334x + 3

I have successfully constructed the divided difference table and got the polynomial in this form:
3 + 1/2(x-1) +1/3(x-1)(x-3/2) - 2(x-1)(x-3/2)x

the values of x's and y's are from an input file
1 1.5 0 2
3 3.25 3 1.67

View Replies View Related

Polynomial Linked List - Store Coefficients

Apr 27, 2015

Write java codes for the following LinkedList base program:

The program should have following three classes:

Node.java , Polynomial.java, Project1.java

A one-variable polynomial of degree n is an arithmetic expression of the form:

a0+a1 x+a2 x^2+..........+an x^n

where a0 a1,a2, ......, an are the coefficients. Design and implement a class named Polynomial that uses a singly-linked list to store the coefficients (so there is virtually no limit on n ). Include a method that adds two polynomials and another method that multiplies two polynomials. For example, the following two polynomials

2 + x^2 - 3x^3 and 1 - x - 2x^2 + 3x^3

are represented by 2, 0, 1, -3 and 1, -1, -2, 3, respectively. The sum of these two polynomials is

3 - x - x^2

which is represented by 3, -1, -1; and the product of the two polynomials is

2 - 2x - 3x^2 + 2x^3 + x^4 + 9x^5 - 9x^6

which is represented by 2, -2, -3, 2, 1, 9, -9.

Note that you must write your code to maintain and manipulate the linked list data structure (i. e., do not use a utility library such as java.util.LinkedList). Email one week before the due date to get a data file to test your program. The data file will contain several pairs of polynomials. Each polynomial is given on a separate line (with coefficients separated by space instead of comma), and there is an empty line between two pairs. Your Java program should read and echo each pair of polynomials, compute and report their sum and product, and go on to process the next pair until the end of input. Specifically, the main method must look like:

while (not end of input) {
read and echo a pair of polynomials P1 and P2;

output sum (P1, P2); // Static method returning a polynomial
output product (P1, P2) // Static method returning a polynomial
}

Hand in a program listing with clear internal documentation and a printout of the results of execution using the test data file. Also email all JAVA program files (Node.java - the same as the one given in class except for the element field that becomes int type for this project, Polynoial.java, Project1.java) so your work can be easily recompiled and tested.

Data file will be like: coefficients of polynomials, not exact, just for as an example of

(The data file will contain several pairs of polynomials)

2 3 0 1 -3

1 -1 -2 3, 9

Output will be in same format with sum and product: coefficients of polynomials, not real, just for as an example.

5 -6 0 7 4

4 -2 -3 3, 7

sum: ...

product:...

...........

View Replies View Related

In And Out Degree Of A Graph

May 2, 2014

I have this code for reading a text file and printing out information about the graph, the program works perfectly but I need to figure out the in degree and out degree of the graph if it is an directed graph. So my question is how would I go about implementing that? I know what in degree and out degree does but in terms of the code I'm not so sure, so I'm thinking if the case of vertex 0,1 the first vertex comes before the second vertex so that would in an in degree right? But how would I do that?

graphs.txt
6,1
0,2 0,4 1,4 1,5 2,1 2,3 2,5 3,2 3,4 4,1 4,5 5,1 5,3 5,2

import java.io.File;
import java.util.Scanner;
 public class Vertices {
public static void main(String[] args) throws Exception {
@SuppressWarnings("resource")

[Code] ....

View Replies View Related

Evaluate Postfix Notation Entered From Keyboard?

Oct 24, 2014

My question is to evaluate a Postfix notation entered from keyboard. I have no errors in my code but it prints only :

Exception in thread "main"

java.util.NoSuchElementException
at ArrayStack.pop(PostFixEvaluation.java:72)
at PostFixEvaluation.evaluatePostfix(PostFixEvaluatio n.java:107)
at PostFixEvaluation.main(PostFixEvaluation.java:140)

I tried many values but it prints the same exception all the time.

Here is my code:

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.NoSuchElementException;
interface Stack<E> {
 
[Code] ....

View Replies View Related

How To Get Correct Postorder In Binary Tree And Evaluate It

Apr 23, 2015

The assignment is meant to understand and practice tree concepts, tree traversals and recursion. I am requested to use the tree to print the expressions by three ways and evaluate the expression in post-order. This is my node class,

package hw10;
public class Node {
String value;
Node left, right;
public Node(String value) {

[Code] .....

When i test my code, some trouble like this:

Enter a prefix expression: - + 10 * 2 8 3
prefix expression:
- + 10 * 2 8 3
postfix expression:
+ 10 * 2 8 3 -
infix expression:
( ( 10 + ( 2 * 8 ) ) - 3 )

[Code] .....

the error lines:

75: double left = evaluate(node.left);
107: evaluate(root);

In the Instruction, which said:

- int evaluate(Node node)

Given the root node of an expression tree, evaluates the expression using post-order traversal and returns the answer. main method Testing logic.

And I found the postfix expression was wrong, it should be: 10 2 8 * + 3 -

I think maybe the tree's order had some problems result in these cases or...

View Replies View Related

Create A Program To Calculate Roots For 2 Degree Equation

Oct 14, 2014

I just created a program to calculate the roots for a 2. degree equation, When I first created my program, I defined the r1 and r2 as double, but got an error saying they needed to be defined as String, why is that?When should I be using string? I am new to java and I have mostly only used int, double and Boolean so far.

import java.util.Scanner;
import java.text.DecimalFormat;
public class c3e1 {
public static void main(String[]args){

[code]....

View Replies View Related

Angling Reflectors 45 Degree - Making It Change Angle With Click

Nov 24, 2014

// scene object variable
var renderer, scene, camera, pointLight, spotLight;

// field variables
var fieldWidth = 400, fieldHeight = 200;

// paddle variables
var paddleWidth, paddleHeight, paddleDepth, paddleQuality;
var paddle1DirY = 0, paddle2DirY = 0, paddleSpeed = 3;

[Code] .....

View Replies View Related

Enterprise JavaBeans :: JPA With 3 Tables - Evaluate Query By Joining 2 Tables And Update Results In 3rd Table

Nov 8, 2013

I have 2 tables on 1 database

Table A, Table B

I need to evaluate a query by joining these 2 tables and then update the results in the 3rd table in another database. I need to use stateless session bean using JPA I believe. I need 3 Entities for each of the tables here.

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved