3
$\begingroup$

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

$\endgroup$
5
  • 1
    $\begingroup$ Towards your questions: 1) You already evaluated the solution many times in Plot3D with y[x1, x2] /. sol (just insert specific valued of x1 and x2). 2) It should now be self-explaratory that the relative error can be computed with (1-y[x1, x2] )/(x1+x2)/. sol (for x1+x2 nonzero). Bonus: You might also be interest in learning about NDSolveValue; it returns an InterpolationFunction instead of a Rule, so it will save you from calling ReplaceAll (/.). $\endgroup$ Commented Mar 8, 2020 at 17:30
  • 1
    $\begingroup$ Dear Henrik, many thanks, I have define x1 = {2, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 2.8, 2.9, 3}; x2 = {2, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 2.8, 2.9, 3}; num = Evaluate[y[x1, x2] /. sol] exact = x1 + x2; relerror = (1 - num)/(exact); error? $\endgroup$
    – user62716
    Commented Mar 8, 2020 at 18:06
  • 1
    $\begingroup$ Only I could not got the error? $\endgroup$
    – user62716
    Commented Mar 8, 2020 at 18:07
  • $\begingroup$ I solve it by exact = {x1 + x2}, thanks $\endgroup$
    – user62716
    Commented Mar 8, 2020 at 18:37
  • $\begingroup$ Yes, I got the answer, thanks $\endgroup$
    – user62716
    Commented Mar 9, 2020 at 18:54

0