// pde11p_eq.java small parts for many points // compile javac -cp . pde11p_eq.java // execute java -cp . pde11p_eq > pde11p_eq_java.out // // solution U(x) = x^4 + 2*x^3 + 3*x^2 + 4*x + 5 // 1st derivative Ux(x) = 4*x^3 + 6*x^2 + 6*x + 4 // 2nd derivative Uxx(x) = 12*x^2 + 12*x + 6 // ode since only one variable Uxx + 2*U = f(x) // f(x) = Uxx(x) + 2*U(x) // f(x) = 2*x^4 + 4*x^3 + 18*x^2 + 20*x + 16 // xmin = -1.0, xmax = 1.0, boundary conditions f(-1.0), f(1.0) import java.text.*; import java.io.*; public class pde11p_eq { int nx = 11; // all of grid includes boundary 0 .. nx-1 int neqn = nx-2; // number of simultaneous equations to solve offset S(i) int npmax = 7; // points for computing numerical derivative by parts boolean debug = true; double xg[] = new double[nx]; double cxx[] = new double[nx]; double xmin = -1.0; double xmax = +1.0; double hx; double error; // sum of absolute exact-computed double avgerror; // average error double rmserror; // root mean square error L2 norm double maxerror; // maximum cell error Linf norm DecimalFormat fe = new DecimalFormat("0.00E00"); DecimalFormat f6 = new DecimalFormat("0.00000"); public pde11p_eq() { System.out.println("pde11p_eq.java running"); System.out.println("uniform grid on line -1 to 1"); System.out.println("PDE to solve Uxx + 2*Ux + 3*U = f(x)"); System.out.println("Uxx(x) + 2*U(x) - 3 = f(x)"); System.out.println("f(x) = 2*x^4 + 4*x^3 + 18*x^2 + 20*x + 13"); System.out.println("known function, for testing method"); System.out.println("U(x) := x^4 + 2*x^3 + 3*x^2 + 4*x + 5"); System.out.println(" "); hx = (xmax-xmin)/(double)(nx-1); System.out.println("xmin="+xmin+", xmax="+xmax+", nx="+nx+", hx="+hx); for(int i=0; i=(np+1)/2 && i=nx-(np+1)/2) // third section upper boundary { new rderiv(2,np,np-(nx-i),hx,cxx); if(debug) System.out.println("xx3 rderiv(2,np,"+(np-(nx-i))+",hx,cxx)"); iv = i-(np-(nx-i))-1; for(int ip=0; ip