sorry if this is a duplicate (I am pretty sure) but I was not able to find the question. I am playing around with DSolve with variable coefficients. In the documentation it is said, that DSolve can handle piecewise defined coefficients, see screenshot below.
Now I am comparing DSolve with NDSolve (with the FEM package) and I get the following results
(*Domain*)
xmin = 0;
xmax = 10;
reg = ImplicitRegion[xmin <= x <= xmax, {x}];
(*Field equation*)
feq = D[A[x]*sig[x], x] + n[x];
sig[x_] := Em[x]*eps[x];
eps[x_] := D[u[x], x];
(*Paremeters*)
Em[x_] :=
Piecewise[{{100,xmin <= x < (xmax - xmin)/3}, {1, (xmax - xmin)/3 <= x <= xmax}}];
A[x_] := 7;
(*Inhomogeneity*)
n[x_] := 3*x;
(*Analytical solution*)
conds = {u[xmin] == 0, u[xmax] == 1};
uds = DSolveValue[{feq == 0, conds}, u, {x, xmin, xmax}];
(*Fem solution*)
Needs["NDSolve`FEM`"]
conds = {DirichletCondition[u[x] == 0, x == xmin],DirichletCondition[u[x] == 1, x == xmax]};
ufem = NDSolveValue[{feq == 0, conds}, u, Element[x, reg]];
(*Plot*)
Plot[{uds[x], ufem[x]}, {x, xmin, xmax}, PlotLegends -> "Expressions"]
And the following plot
The results of uds are wrong, while ufem is correct. Already for n=0 I get the plot
where uds is wrong.
Question: do you see where my error in DSolve is? Is DSolve not able to handle piecewise defined coefficients? Thank you!