php22_eq.php solve partial differential equation
// deriv.php includes deriv, rderiv, nuderiv require_once 'deriv.php';
// order is order of derivative, 1 = first derivative, 2 = second
// points is number of points where value of function is known
// f(x0), f(x1), f(x2) ... f(x points-1)
// point is the term where derivative is computed
// f'(x0) = (1/bh^order)*( a(0)*f(x0) + a(1)*f(x1)
// + ... + a(points-1)*f(x points-1)
// uniformly spaced points x1=x0+h, x2=x1+h=x1+2*h, ...
//
// rderiv returns c[0]=(1/bh^order)*a[0] ...
//
// nuderiv works for non-uniformly spaced points
//
// algorithm: use divided differences to get polynomial p(x) that
// approximates f(x). f(x)=p(x)+error term
// f'(x) = p'(x) + error term'
// substitute xj = x0 + j*h
// substitute x = x0 to get p'(x0) etc
pde22_eq.c running
differential equation to solve
d^2u/dx^2 + d^2u/dy^2 = c(x,y)
Uxx(x,y) = 2^16 *
12*x^2 * (1-x)^4 * y^4 * (1-y)^4 -
32*x^3 * (1-x)^3 * y^4 * (1-y)^4 +
12*x^4 * (1-x)^2 * y^4 * (1-y)^4;
Uyy(x,y) = 2^16 *
12*x^4 * (1-x)^4 * y^2 * (1-y)^4 -
32*x^4 * (1-x)^4 * y^3 * (1-y)^3 +
12*x^4 * (1-x)^4 * y^4 * (1-y)^2;
c(x,y) = Uxx(x,y) + Uyy(x,y);
uniform grid on rectangle 0,1 to 0,1
known Solution, for testing method
u(x,y) = 2^16*x^4*(1-x)^4*y^4*(1-y)4
xg[0]=0
xg[1]=0.11111111111111
xg[2]=0.22222222222222
xg[3]=0.33333333333333
xg[4]=0.44444444444444
xg[5]=0.55555555555556
xg[6]=0.66666666666667
xg[7]=0.77777777777778
xg[8]=0.88888888888889
xg[9]=1
yg[0]=0
yg[1]=0.11111111111111
yg[2]=0.22222222222222
yg[3]=0.33333333333333
yg[4]=0.44444444444444
yg[5]=0.55555555555556
yg[6]=0.66666666666667
yg[7]=0.77777777777778
yg[8]=0.88888888888889
yg[9]=1
xmin=0, xmax=1, hx=0.11111111111111, nx=10
ymin=0, ymax=1, hy=0.11111111111111, ny=10
neqn=64 solution points inside boundary
u(0.5,0.5)=1
c(0.5,0.5)=-64
initialized ut matrix
internal cells zeroed
matrix initialized
solve simultaneous equations
exact solution u, computed us, error
xg[1]=0.11111111111111, yg[1]=0.11111111111111, u=0.00059336192578521 us=0.0005933619305069, err=4.7216876675887E-12
xg[1]=0.11111111111111, yg[2]=0.22222222222222, u=0.0055650858742589 us=0.0055650858819403, err=7.6813885113713E-12
xg[1]=0.11111111111111, yg[3]=0.33333333333333, u=0.015207217168269 us=0.015207217179591, err=1.1322179305218E-11
xg[1]=0.11111111111111, yg[4]=0.44444444444444, u=0.023178200225985 us=0.023178200239236, err=1.3251427732897E-11
xg[1]=0.11111111111111, yg[5]=0.55555555555556, u=0.023178200225985 us=0.023178200237004, err=1.1019612305985E-11
xg[1]=0.11111111111111, yg[6]=0.66666666666667, u=0.015207217168269 us=0.015207217172895, err=4.6262507713557E-12
xg[1]=0.11111111111111, yg[7]=0.77777777777778, u=0.0055650858742589 us=0.0055650858713766, err=2.8823610165318E-12
xg[1]=0.11111111111111, yg[8]=0.88888888888889, u=0.00059336192578521 us=0.00059336191794466, err=7.8405478724092E-12
xg[2]=0.22222222222222, yg[1]=0.11111111111111, u=0.0055650858742589 us=0.005565085881939, err=7.6800675194444E-12
xg[2]=0.22222222222222, yg[2]=0.22222222222222, u=0.052194418687874 us=0.05219441869392, err=6.0460456086098E-12
xg[2]=0.22222222222222, yg[3]=0.33333333333333, u=0.14262706414458 us=0.14262706414924, err=4.6574688550294E-12
xg[2]=0.22222222222222, yg[4]=0.44444444444444, u=0.21738616696324 us=0.21738616696539, err=2.145728039693E-12
xg[2]=0.22222222222222, yg[5]=0.55555555555556, u=0.21738616696324 us=0.21738616696096, err=2.277150690233E-12
xg[2]=0.22222222222222, yg[6]=0.66666666666667, u=0.14262706414458 us=0.14262706413538, err=9.2048035860159E-12
xg[2]=0.22222222222222, yg[7]=0.77777777777778, u=0.052194418687874 us=0.052194418671065, err=1.6809380276595E-11
xg[2]=0.22222222222222, yg[8]=0.88888888888889, u=0.0055650858742589 us=0.0055650858489408, err=2.5318159027621E-11
xg[3]=0.33333333333333, yg[1]=0.11111111111111, u=0.015207217168269 us=0.015207217179593, err=1.1324375465138E-11
xg[3]=0.33333333333333, yg[2]=0.22222222222222, u=0.14262706414458 us=0.14262706414924, err=4.6583570334491E-12
xg[3]=0.33333333333333, yg[3]=0.33333333333333, u=0.38974434312895 us=0.38974434312881, err=1.3156142841808E-13
xg[3]=0.33333333333333, yg[4]=0.44444444444444, u=0.59403192063549 us=0.59403192063005, err=5.4377613523116E-12
xg[3]=0.33333333333333, yg[5]=0.55555555555556, u=0.59403192063549 us=0.59403192062377, err=1.1719403225641E-11
xg[3]=0.33333333333333, yg[6]=0.66666666666667, u=0.38974434312895 us=0.38974434310829, err=2.0653534438253E-11
xg[3]=0.33333333333333, yg[7]=0.77777777777778, u=0.14262706414458 us=0.14262706411409, err=3.0492441904784E-11
xg[3]=0.33333333333333, yg[8]=0.88888888888889, u=0.015207217168269 us=0.015207217120654, err=4.761418516408E-11
xg[4]=0.44444444444444, yg[1]=0.11111111111111, u=0.023178200225985 us=0.023178200239236, err=1.3251216096632E-11
xg[4]=0.44444444444444, yg[2]=0.22222222222222, u=0.21738616696324 us=0.21738616696539, err=2.1464774402347E-12
xg[4]=0.44444444444444, yg[3]=0.33333333333333, u=0.59403192063549 us=0.59403192063005, err=5.4389825976386E-12
xg[4]=0.44444444444444, yg[4]=0.44444444444444, u=0.90539844632753 us=0.90539844631471, err=1.2814971306341E-11
xg[4]=0.44444444444444, yg[5]=0.55555555555556, u=0.90539844632753 us=0.90539844630734, err=2.0190626948136E-11
xg[4]=0.44444444444444, yg[6]=0.66666666666667, u=0.59403192063549 us=0.59403192060535, err=3.0144775564622E-11
xg[4]=0.44444444444444, yg[7]=0.77777777777778, u=0.21738616696324 us=0.21738616692218, err=4.1057796051902E-11
xg[4]=0.44444444444444, yg[8]=0.88888888888889, u=0.023178200225985 us=0.023178200161283, err=6.4702226215685E-11
xg[5]=0.55555555555556, yg[1]=0.11111111111111, u=0.023178200225985 us=0.023178200237008, err=1.1023380125375E-11
xg[5]=0.55555555555556, yg[2]=0.22222222222222, u=0.21738616696324 us=0.21738616696096, err=2.2770951790818E-12
xg[5]=0.55555555555556, yg[3]=0.33333333333333, u=0.59403192063549 us=0.59403192062377, err=1.1719958337153E-11
xg[5]=0.55555555555556, yg[4]=0.44444444444444, u=0.90539844632753 us=0.90539844630734, err=2.0190960015043E-11
xg[5]=0.55555555555556, yg[5]=0.55555555555556, u=0.90539844632753 us=0.90539844629996, err=2.756672667914E-11
xg[5]=0.55555555555556, yg[6]=0.66666666666667, u=0.59403192063549 us=0.59403192059907, err=3.6425196192624E-11
xg[5]=0.55555555555556, yg[7]=0.77777777777778, u=0.21738616696324 us=0.21738616691776, err=4.5477926979842E-11
xg[5]=0.55555555555556, yg[8]=0.88888888888889, u=0.023178200225985 us=0.023178200159059, err=6.6925503333648E-11
xg[6]=0.66666666666667, yg[1]=0.11111111111111, u=0.015207217168269 us=0.015207217172893, err=4.6245177826032E-12
xg[6]=0.66666666666667, yg[2]=0.22222222222222, u=0.14262706414458 us=0.14262706413538, err=9.2026386511179E-12
xg[6]=0.66666666666667, yg[3]=0.33333333333333, u=0.38974434312895 us=0.38974434310829, err=2.065431159437E-11
xg[6]=0.66666666666667, yg[4]=0.44444444444444, u=0.59403192063549 us=0.59403192060534, err=3.0146884988369E-11
xg[6]=0.66666666666667, yg[5]=0.55555555555556, u=0.59403192063549 us=0.59403192059907, err=3.6426195393346E-11
xg[6]=0.66666666666667, yg[6]=0.66666666666667, u=0.38974434312895 us=0.38974434308777, err=4.117423069161E-11
xg[6]=0.66666666666667, yg[7]=0.77777777777778, u=0.14262706414458 us=0.14262706410024, err=4.4344777849759E-11
xg[6]=0.66666666666667, yg[8]=0.88888888888889, u=0.015207217168269 us=0.01520721711397, err=5.4298829321731E-11
xg[7]=0.77777777777778, yg[1]=0.11111111111111, u=0.0055650858742589 us=0.0055650858713933, err=2.8656434863938E-12
xg[7]=0.77777777777778, yg[2]=0.22222222222222, u=0.052194418687874 us=0.052194418671068, err=1.6805543068266E-11
xg[7]=0.77777777777778, yg[3]=0.33333333333333, u=0.14262706414458 us=0.14262706411409, err=3.049113739273E-11
xg[7]=0.77777777777778, yg[4]=0.44444444444444, u=0.21738616696324 us=0.21738616692218, err=4.1059128319532E-11
xg[7]=0.77777777777778, yg[5]=0.55555555555556, u=0.21738616696324 us=0.21738616691776, err=4.5479092714018E-11
xg[7]=0.77777777777778, yg[6]=0.66666666666667, u=0.14262706414458 us=0.14262706410024, err=4.4344139471519E-11
xg[7]=0.77777777777778, yg[7]=0.77777777777778, u=0.052194418687874 us=0.052194418648225, err=3.9648631600109E-11
xg[7]=0.77777777777778, yg[8]=0.88888888888889, u=0.0055650858742589 us=0.0055650858384151, err=3.5843822701609E-11
xg[8]=0.88888888888889, yg[1]=0.11111111111111, u=0.00059336192578521 us=0.00059336191796503, err=7.8201775567319E-12
xg[8]=0.88888888888889, yg[2]=0.22222222222222, u=0.0055650858742589 us=0.0055650858489479, err=2.5311019773155E-11
xg[8]=0.88888888888889, yg[3]=0.33333333333333, u=0.015207217168269 us=0.015207217120654, err=4.7614433229537E-11
xg[8]=0.88888888888889, yg[4]=0.44444444444444, u=0.023178200225985 us=0.023178200161278, err=6.4706382613133E-11
xg[8]=0.88888888888889, yg[5]=0.55555555555556, u=0.023178200225985 us=0.023178200159057, err=6.6927626635183E-11
xg[8]=0.88888888888889, yg[6]=0.66666666666667, u=0.015207217168269 us=0.015207217113973, err=5.4295809168159E-11
xg[8]=0.88888888888889, yg[7]=0.77777777777778, u=0.0055650858742589 us=0.0055650858384178, err=3.5841128676051E-11
xg[8]=0.88888888888889, yg[8]=0.88888888888889, u=0.00059336192578521 us=0.00059336190542499, err=2.0360218285637E-11
avg_error=2.3455562794163E-11, max_error=6.6927626635183E-11
finished pde22_eq.php