1 package practice;
2 // http://introcs.cs.princeton.edu/java/92symbolic/Polynomial.java.html3 /*************
4 * Compilation: javac Polynomial.java
5 * Execution: java Polynomial
6 *
7 * Polynomials with integer coefficients.
8 *
9 * % java Polynomial
10 * zero(x) = 0
11 * p(x) = 4x^3 + 3x^2 + 2x + 1
12 * q(x) = 3x^2 + 5
13 * p(x) + q(x) = 4x^3 + 6x^2 + 2x + 6
14 * p(x) * q(x) = 12x^5 + 9x^4 + 26x^3 + 18x^2 + 10x + 5
15 * p(q(x)) = 108x^6 + 567x^4 + 996x^2 + 586
16 * 0 – p(x) = -4x^3 – 3x^2 – 2x – 1
17 * p(3) = 142
18 * p'(x) = 12x^2 + 6x + 2
19 * p”(x) = 24x + 6
20 *
21 ************/
22 public class Polynomial {
23 private int[] coef; //coefficients 系数24 private int deg;//degree of polynomial (0 for the zero polynomial)
25 26 //ax^b 27 public Polynomial(int a, int b){
28 coef = new int[b+1];
29 coef[b] = a;
30 deg = degree();
31 }
32
33 //return the degree of this polynomial (0 for the zero polynomial)34 public int degree(){
35 int d = 0;
36 for(int i = 0; i
Original: https://www.cnblogs.com/springfor/p/4001249.html
Author: 爱做饭的小莹子
Title: 实现多项式的JAVA类
原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/539438/
转载文章受原作者版权保护。转载请注明原作者出处!