I am trying to multiply an interpolating function by -1. If I do this Mathematica does not seem to allow any further operations. Bear with me while I generate the Interpolating Function in question. It is a derivative of the output of NDSolve.
Clear["Global`*"];
Remove["Global`*"];
center = Rectangle[{-.1, -.1}, {.1, .1}];
shield = Rectangle[{-1, -1}, {1, 1}];
reg = RegionDifference[shield, center];
uif = NDSolveValue[{\!\(
\*SubsuperscriptBox[\(\[Del]\), \({x, y}\), \(2\)]\(u[x, y]\)\) == 0,
DirichletCondition[u[x, y] == 0, x^2 + y^2 >= .5],
DirichletCondition[u[x, y] == 1, x^2 + y^2 < .5]},u, {x, y} \[Element] reg]
partialx = Derivative[1, 0][uif];
NIntegrate[partialx[.5, y], {y, -.5, .5}, AccuracyGoal -> 3]
Plot[partialx[x, -.5], {x, -1, 1}]
At this point everything is fine. NIntegrate and Plot work.
However, this code does not work.
partialxneg = -1*Derivative[1, 0][uif];
NIntegrate[partialxneg[.5, y], {y, -.5, .5}, AccuracyGoal -> 3]
Plot[partialxneg[x, -.5], {x, -1, 1}]
NIntegrate fails with
The integrand (-InterpolatingFunction[{{-1., 1.}, {-1., 1.}}, {4, 4225, 0, {1320, 0}, {3, 3}, {1 ,0}, 0, 0, 0, Automatic, {}, {}, False}, {NDSolve
FEM
ElementMesh[{{-1., -1.}, {-1., -0.875}, <<47>>, {0.875, -1.}, <<1270>>}, <<2>>, {<<24>>[{{<<1>>}, <<49>>, <<94>>}]}]}, {0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,0., 0., 0., 0., <<1270>>}, {Automatic}])[<<1>>] has evaluated to non-numerical values for all sampling points in the region with boundaries {{-0.5, 0.5}}. >>
Also, Plot does not plot anything.
All I did was multiply the derivative by -1.
Method -> {"FiniteElement", "MeshOptions" -> {"MaxCellMeasure" -> 0.001}}
to get a better resolution of theNDSolve
result. $\endgroup$ – user21 Aug 4 '14 at 6:27