rendered paste bodypublic class TestMaman17 {
public static void main (String [] args) {
System.out.println ("*** 1st Polynom ***");
Polynom p1 = new Polynom ();
PolyNode n1 = new PolyNode(5,-1.0);
PolyNode n2 = new PolyNode(2,2.0);
PolyNode n3 = new PolyNode(3,-3.0);
PolyNode n4 = new PolyNode(7,4.0);
PolyNode n5 = new PolyNode(1,-5.0);
PolyNode n6 = new PolyNode(4,6.0);
PolyNode n7 = new PolyNode(3,1.0);
PolyNode n8 = new PolyNode(7,-2.0);
p1.addNode (n1);
System.out.println (p1);
p1.addNode (n2);
System.out.println (p1);
p1.addNode (n3);
System.out.println (p1);
p1.addNode (n4);
System.out.println (p1);
p1.addNode (n5);
System.out.println (p1);
p1.addNode (n6);
System.out.println (p1);
System.out.println ("*** adding node with 1.0x^3 ***");
p1.addNode (n7);
System.out.println (p1);
System.out.println ("*** adding node with -2.0x^7 ***");
p1.addNode (n8);
System.out.println (p1);
System.out.println ("*** 2nd Polynom ***");
PolyNode n11 = new PolyNode(8,-1.0);
PolyNode n12 = new PolyNode(0,2.0);
PolyNode n13 = new PolyNode(3,-3.0);
PolyNode n14 = new PolyNode(5,4.0);
PolyNode n15 = new PolyNode(6,-5.0);
Polynom p2 = new Polynom (n11);
System.out.println (p2);
p2.addNode (n12);
System.out.println (p2);
p2.addNode (n13);
System.out.println (p2);
p2.addNode (n14);
System.out.println (p2);
p2.addNode (n15);
System.out.println (p2);
System.out.println ("*** Adding 1st and 2nd polynom ***");
System.out.println ("1st: " +p1);
System.out.println ("2nd: " +p2);
Polynom p9 = p1.addPol (p2);
System.out.println ("1st + 2nd: " +p9);
Polynom p10 = p2.addPol (p1);
System.out.println ("2nd + 1st: " + p10);
System.out.println ("*** differential 1st polynom ***");
System.out.println ("1st: " +p1);
Polynom p5 = p1.differential();
System.out.println ("diff: " +p5);
System.out.println ("*** differential 2nd polynom ***");
System.out.println ("2nd: "+p2);
Polynom p6 = p2.differential();
System.out.println ("diff: " +p6);
System.out.println ("*** 1st Polynom multiply by scalar ***");
System.out.println ("1st:"+p1);
Polynom p7 = p1.multByScalar (2);
System.out.println ("times 2: "+p7);
System.out.println ("*** 2nd Polynom multiply by scalar ***");
System.out.println ("2nd: "+p2);
Polynom p8 = p2.multByScalar (-3);
System.out.println ("times -3: "+ p8);
System.out.println ("*** 3rd Polynom ***");
Polynom p3 = new Polynom ();
PolyNode n23 = new PolyNode(3,8.0);
PolyNode n22 = new PolyNode(2,-3.0);
PolyNode n21 = new PolyNode(1,-1.0);
PolyNode n24 = new PolyNode(0,7.0);
p3.addNode (n21);
System.out.println (p3);
p3.addNode (n22);
System.out.println (p3);
p3.addNode (n23);
System.out.println (p3);
p3.addNode (n24);
System.out.println (p3);
System.out.println ("*** 4th Polynom ***");
PolyNode n33 = new PolyNode(2,1.0);
PolyNode n32 = new PolyNode(1,6.0);
PolyNode n31 = new PolyNode(0,-15.0);
Polynom p4 = new Polynom ();
p4.addNode (n31);
System.out.println (p4);
p4.addNode (n32);
System.out.println (p4);
p4.addNode (n33);
System.out.println (p4);
System.out.println ("*** multiplying 3rd and 4th polynom ***");
System.out.println ("*** same ones used in the Maman example ***");
System.out.println ("3rd: " +p3);
System.out.println ("4th: " +p4);
Polynom p11 = p3.multPol (p4);
System.out.println ("3rd * 4th: "+p11);
Polynom p12 = p4.multPol (p3);
System.out.println ("4th * 3rd: " +p12);
System.out.println ("*** multiplying 1st and 2nd polynom ***");
System.out.println ("1st: " +p1);
System.out.println ("2nd: " +p2);
Polynom p13 = p1.multPol (p2);
System.out.println ("1st * 2nd: "+p13);
Polynom p14 = p2.multPol (p1);
System.out.println ("2nd * 1st: " +p14);
}
}
Output should be:
*** 1st Polynom ***
-1.0x^5
-1.0x^5 +2.0x^2
-1.0x^5 -3.0x^3 +2.0x^2
4.0x^7 -1.0x^5 -3.0x^3 +2.0x^2
4.0x^7 -1.0x^5 -3.0x^3 +2.0x^2 -5.0x^1
4.0x^7 -1.0x^5 +6.0x^4 -3.0x^3 +2.0x^2 -5.0x^1
*** adding node with 1.0x^3 ***
4.0x^7 -1.0x^5 +6.0x^4 -2.0x^3 +2.0x^2 -5.0x^1
*** adding node with -2.0x^7 ***
2.0x^7 -1.0x^5 +6.0x^4 -2.0x^3 +2.0x^2 -5.0x^1
*** 2nd Polynom ***
-1.0x^8
-1.0x^8 +2.0
-1.0x^8 -3.0x^3 +2.0
-1.0x^8 +4.0x^5 -3.0x^3 +2.0
-1.0x^8 -5.0x^6 +4.0x^5 -3.0x^3 +2.0
*** Adding 1st and 2nd polynom ***
1st: 2.0x^7 -1.0x^5 +6.0x^4 -2.0x^3 +2.0x^2 -5.0x^1
2nd: -1.0x^8 -5.0x^6 +4.0x^5 -3.0x^3 +2.0
1st + 2nd: -1.0x^8 +2.0x^7 -5.0x^6 +3.0x^5 +6.0x^4 -5.0x^3 +2.0x^2 -5.0x^1 +2.0
2nd + 1st: -1.0x^8 +2.0x^7 -5.0x^6 +3.0x^5 +6.0x^4 -5.0x^3 +2.0x^2 -5.0x^1 +2.0
*** differential 1st polynom ***
1st: 2.0x^7 -1.0x^5 +6.0x^4 -2.0x^3 +2.0x^2 -5.0x^1
diff: 14.0x^6 -5.0x^4 +24.0x^3 -6.0x^2 +4.0x^1 -5.0
*** differential 2nd polynom ***
2nd: -1.0x^8 -5.0x^6 +4.0x^5 -3.0x^3 +2.0
diff: -8.0x^7 -30.0x^5 +20.0x^4 -9.0x^2 +0.0x^-1
*** 1st Polynom multiply by scalar ***
1st:2.0x^7 -1.0x^5 +6.0x^4 -2.0x^3 +2.0x^2 -5.0x^1
times 2: 4.0x^7 -2.0x^5 +12.0x^4 -4.0x^3 +4.0x^2 -10.0x^1
*** 2nd Polynom multiply by scalar ***
2nd: -1.0x^8 -5.0x^6 +4.0x^5 -3.0x^3 +2.0
times -3: 3.0x^8 +15.0x^6 -12.0x^5 +9.0x^3 -6.0
*** 3rd Polynom ***
-1.0x^1
-3.0x^2 -1.0x^1
8.0x^3 -3.0x^2 -1.0x^1
8.0x^3 -3.0x^2 -1.0x^1 +7.0
*** 4th Polynom ***
-15.0
6.0x^1 -15.0
1.0x^2 +6.0x^1 -15.0
*** multiplying 3rd and 4th polynom ***
*** same ones used in the Maman example ***
3rd: 8.0x^3 -3.0x^2 -1.0x^1 +7.0
4th: 1.0x^2 +6.0x^1 -15.0
3rd * 4th: 8.0x^5 +45.0x^4 -139.0x^3 +46.0x^2 +57.0x^1 -105.0
4th * 3rd: 8.0x^5 +45.0x^4 -139.0x^3 +46.0x^2 +57.0x^1 -105.0
*** multiplying 1st and 2nd polynom ***
1st: 2.0x^7 -1.0x^5 +6.0x^4 -2.0x^3 +2.0x^2 -5.0x^1
2nd: -1.0x^8 -5.0x^6 +4.0x^5 -3.0x^3 +2.0
1st * 2nd: -2.0x^15 -9.0x^13 +2.0x^12 +7.0x^11 -42.0x^10 +39.0x^9 -15.0x^8 +19.0x^7 -14.0x^6 -8.0x^5 +27.0x^4 -4.0x^3 +4.0x^2 -10.0x^1
2nd * 1st: -2.0x^15 -9.0x^13 +2.0x^12 +7.0x^11 -42.0x^10 +39.0x^9 -15.0x^8 +19.0x^7 -14.0x^6 -8.0x^5 +27.0x^4 -4.0x^3 +4.0x^2 -10.0x^1