// Chebyshev.java Chebyshev (or Tschebycheff) polynomials and quadrature // // T0(x)=1 T1(x)=x Tn+1(x)=2*x*Tn(x) - Tn-1(x) // T2(x)=2 x^2 - 1 T3(x)=4 x^3 - 3 x T4(x)=8 x^4 -8 x^2 + 1 // int -1 to 1 of f(x)dx = sum i=1,n w[i] F(x[i]) // w[i]= 1/sqrt(1-x[i]^2) // x[i]= roots of Tn(x) // // n=2 x= +/- .5773502692 w=1.0 // n=3 x= +/- .7745966692 w= .5555555556 // 0.0 .8888888889 // n=4 x= +/- .8611363116 w= .3478546451 // +/- .3399810436 .6521451549 // n=5 x= +/- .9061798459 .2369268851 // +/- .5384693101 .4786286705 // 0.0 .5688888889 // // conversion/scaling int a to b of f(x)dx = // (b-a)/2 int -1 to 1 of f((a+b+x*(b-a))/2)dx // // Chebyshev quadrature, integrate f(x) from -1 to 1 // int -1 to 1 f(x) dx = sum i=0,n-1 w[i]f(x[i]) import java.awt.*; import java.awt.event.*; public class Chebyshev extends Frame { int N=15; // change to max polynomial size double T[][] = new double[N][N+1]; // coefficients of Tn(x) double R[][] = new double[N][N]; // roots of Tn(x) the x[i] double W[][] = new double[N][N]; // weights of Tn(x) the w[i] double Td[][] = new double[N][N]; // derivitive public Chebyshev() { System.out.println("Chebyshev.java running"); // generate family of Chebyshev polynomials Tn(x) // as T[degree][coefficients] // build coefficients of Tn(x) for(int n=0; n4.95) ynew=4.95; if(ynew<-4.95) ynew=-4.95; if(x!=-1.0) // not first time { g.drawLine((int)(f2xC+(xold/1.0)*sca), (int)(f2yC-(yold/5.0)*sca), (int)(f2xC+(xnew/1.0)*sca), (int)(f2yC-(ynew/5.0)*sca)); } xold=xnew; yold=ynew; } } g.setColor(Color.red); Font cur16 = new Font("courier", Font.BOLD, 16); g.setFont(cur16); g.drawString("y=Tn(x)", 55, 50); g.drawString("y=T'n(x)", 355, 50); g.setColor(col[0]); g.drawString("T2(x) ____", 55, 310); g.setColor(col[1]); g.drawString("T3(x) ____", 55, 330); g.setColor(col[2]); g.drawString("T4(x) ____", 55, 350); g.setColor(col[3]); g.drawString("T5(x) ____", 55, 370); g.setColor(col[0]); g.drawString("T'2(x) ____", 355, 310); g.setColor(col[1]); g.drawString("T'3(x) ____", 355, 330); g.setColor(col[2]); g.drawString("T'4(x) ____", 355, 350); g.setColor(col[3]); g.drawString("T'5(x) ____", 355, 370); g.setColor(Color.black); g.drawString("Chebyshev Polynomials and derivatives", 100, 390); } private static double evaluate(int n, double T[], double x) { double value=T[n]; for(int i=n-1; i>=0; i--) value = value*x+T[i]; return value; } public static void main (String[] args) // demo { new Chebyshev(); // construct and execute } }