/* pdenu24_eq.c 2D non uniform grid boundary value PDE */ /* known solution to test method */ /* u(x,y) = sin(x)+cos(y) */ /* */ /* differential equation to solve */ /* du/dy + d^4u/dx^4 + d^2u/dx^2 - du/dx = -sin(y)-cos(x) */ /* */ /* non uniform grid on rectangle 0.0,0.1 to 1.0,1.0 */ /* */ /* set up and solve system of linear equations */ /* */ /* create two dimensional array with */ /* (nx-2)*(ny-2) rows, one for each equation */ #include "nuderiv.h" #include #include #include #undef abs #define abs(a) ((a)<0.0?(-(a)):(a)) #undef min #define min(a,b) ((a)<(b)?(a):(b)) #undef max #define max(a,b) ((a)>(b)?(a):(b)) #define nx 17 /* includes boundary */ #define ny 17 /* includes boundary */ /* static double xg[nx] = {0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0}; static double yg[ny] = {0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0}; */ static double xg[nx]; /* includes boundary */ static double yg[ny]; static double cx[nx]; /* nuderiv coefficients */ static double cxx[nx]; static double cxxxx[nx]; static double cy[ny]; static double coefdy, coefdx, coefdxx, coefdxxxx; /* nx-2 by ny-2 internal, non boundary cells */ static double us[(nx-2)*(ny-2)]; /* solution being computed */ static double ut[(nx-2)*(ny-2)][(nx-2)*(ny-2)+1]; /* temporary equations */ static double error; /* sum of absolute exact-computed */ static double avgerror; /* average error */ static double maxerror; /* maximum cell error */ static double u(double x, double y) /* for boundary and optional check */ { return sin(x)+cos(y); } static double c(double x, double y) /* RHS of differential equation to solve */ { return -cos(x)-sin(y); } static void check() /* typically not known, instrumentation */ { int i, j; double uexact, err; error = 0.0; maxerror = 0.0; for(i=1; imaxerror) maxerror=err; } } } /* end check */ static void printus() { int i, j; printf("computed solution\n"); for(i=1; i abs_pivot) { i_pivot = i; pivot = B[row[i]][k]; abs_pivot = abs ( pivot ); } } /* have pivot, interchange row pointers */ hold = row[k]; row[k] = row[i_pivot]; row[i_pivot] = hold; /* check for near singular */ if( abs_pivot < 1.0E-10 ) { for(j=k+1; j