# Defining a function in terms of interpolating functions

I had a question regarding multiplying an interpolation function with a regular function such as

Let f and g be two interpolation functions in the domain defined by $0 \le x \le 1$ and $0 \le y \le 1$

then how do you compute $(1+x^2) \frac{df}{dx} + \frac{dg}{dx}$ ?

I tried

h = Evaluate[D[f, {x, 1}]](1 + x^2) + Evaluate[D[g, {x, 1}]]


but it doesn't work because we can't sum two interpolation functions.

Therefore, I tried

h =
FunctionInterpolation[
Evaluate[D[f, {x, 1}]](1 + x^2) + Evaluate[D[g, {x, 1}]], {x, 0, 1}, {y, 0, 1}]


This works, however I wanted to check the accuracy of the derivative just to make sure everything is correct, so I computed

temp1 = FunctionInterpolation[Evaluate[D[f, {x, 1}]], {x, 0, 1},{y, 0, 1}]
temp2 = Evaluate[D[f, {x, 1}]]


and evaluate it at x = 0.5 and y = 0.5. The results of temp1 and temp2 have deviations. Is there a better way to do this. I would appreciate any advice I can get.

• Does f'[x] (1 + x^2) + g'[x] work? – kglr Oct 15 '17 at 23:17
• Where are f and g coming from? – J. M.'s technical difficulties Oct 16 '17 at 3:02
• f and g solutions from a finite element problem over a finite element mesh – KVK318 Oct 16 '17 at 14:03

It seems straightforward to me. Note that I do the interpolation on data points of the form {x, f[x]} to get the domain right, and that I do not explicitly call Evaluate in this code.

f = Interpolation[Table[{x, Sin[2 π x]}, {x, 0, 1, .01}]];
g = Interpolation[Table[{x, Cos[2 π x]}, {x, 0, 1, .01}]];

h[x_] = (1 + x^2) f'[x] + g'[x];


Now let's plot h against its exact form

hx[x_] = (1 + x^2) D[Sin[2 π x], x] + D[Cos[2 π x], x]


The combined plot shows that h and hx conform as well as can be expected.

Plot[{h[x], hx[x]}, {x, 0, 1},
PlotStyle -> {Directive[AbsoluteThickness], AbsoluteThickness[1.5]},
PlotLegends -> {h, hx}] 