I have got the help from the expert ''Nasser'' to write the code for the PDE with variable coefficients and mixed boundary conditions define on a square domain:
ClearAll[y, x1, x2];
a = x1 + x2;
pde = D[a D[y[x1, x2], x1], x1] + D[a D[y[x1, x2], x2], x2] - 4;
bc = {y[x1, 2] == 2 + x1, y[x1, 3] == 3 + x1};
sol = NDSolve[{pde ==
NeumannValue[-1*a, x2 == 2] + NeumannValue[1*a, x2 == 3], bc},
y, {x1, 2, 3}, {x2, 2, 3}]
Plot3D[Evaluate[y[x1, x2] /. sol], {x1, 2, 3}, {x2, 2, 3},
PlotRange -> All, AxesLabel -> {"x1", "X2", "y[x1,x2]"},
BaseStyle -> 12]
where the Neumann BC is define for this problem as a(x)dy/dn which is equal to a(x)(grad(y,x1)*n1+grad(y,x2)n2) which is equal in this probem (as we took the know just to check the accuracy y=x1+x2) =a(x)(1*n1+1*n2)=a(x)*(n1+n2), we n1,n2 are component of normal vector.
Can we 1) evalue the numerical values of the solution on the domail?
2) can we evaluate the say relative error between the numerical and the exact which is equal to y=x1+x2?
Best regards
Plot3D
withy[x1, x2] /. sol
(just insert specific valued ofx1
andx2
). 2) It should now be self-explaratory that the relative error can be computed with(1-y[x1, x2] )/(x1+x2)/. sol
(forx1+x2
nonzero). Bonus: You might also be interest in learning aboutNDSolveValue
; it returns anInterpolationFunction
instead of aRule
, so it will save you from callingReplaceAll
(/.
). $\endgroup$