Google Answers Logo
View Question
 
Q: Java Polynomial ( No Answer,   0 Comments )
Question  
Subject: Java Polynomial
Category: Computers > Programming
Asked by: barnameh-ga
List Price: $20.00
Posted: 10 Oct 2005 10:24 PDT
Expires: 10 Oct 2005 22:19 PDT
Question ID: 578519
This is my Main class, now I need to define the polynomial for this
class first then do some more to it, I just wrote the main parts that
I need help for.
1. I don't know how to define this, whatever I try does not work. 
2. If you can do the addition (plus), I can do the rest. 
3. I am not sure how to define the cline as well, I couldn't find it in api. 
I think someone asked a similar question on Nov 2004. His question ID # is 425157. 
Thanks. 

package F03;

public class Main
{  public static void main(String[] args)
   {

       //Construct a polynomial p(t) = -5.2 + 9.85t + 6.5t^2 - 193.04t^3
       Polynomial p1;
       double[] a = {-5.2, 9.85, 6.5, -193.04};
       p1 = new Polynomial(a);
       System.out.println("\n\nShould get:\n-5.2 + 9.85t + 6.5t^2 - 193.04t^3");
       System.out.println("Actaully returns: \n" + p1.toPrettyStr() + "\n\n");

       //Construct a polynomial q(t) = 1.7 + 1.1t - 8.03t^2 in a
rather peculiar way
       Polynomial p2 = new Polynomial();//Construct a polynomial 0
       double[] b = {1.7, 1.1, -8.03};
       for(int j = 0; j < b.length; j++)
       {  Polynomial temp = new Polynomial(b[j], j);
          p2 = Polynomial.plus(p2, temp); //add b[j]t^j to q(t)
       }
       System.out.println("\n\nShould get:\nq(t) = 1.7 + 1.1t - 8.03t^2");
       System.out.println("Actaully returns: " + "\n" + p2.toPrettyStr() + "\n\n");


       Polynomial p3 = Polynomial.plus(p1, p2);
       System.out.println("\n\n\nShould get:\n1.3 + 0.65t^1 + 4.93t^2
- 123.34t^3");
       System.out.println("Actaully returns: \n" + p3.toPrettyStr());


       Polynomial p6 = (Polynomial) p1.clone();
       p1.setCoeff(3, 54.1);
       System.out.println("\n\n\nShould get:\n-5.2 + 9.85t + 6.5t^2 - 193.04t^3");
       System.out.println("Actaully returns: \n" + p6.toPrettyStr());
       System.out.println("\nShouold get: \n-5.2 + 9.85t + 6.5t^2 - 193.04t^3");
       System.out.println("Actaully returns: \n" + p1.toPrettyStr());
//t4 should be different        from p

       System.out.println("\n\n\nShould get\n?");
       System.out.println("Actaully returns: \n" + p6.eval(2.13));

       System.out.println("\n\n\n");

   }
}
Answer  
There is no answer at this time.

Comments  
There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy