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");
}
} |