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 = 
    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.

  • $\begingroup$ Does f'[x] (1 + x^2) + g'[x] work? $\endgroup$ – kglr Oct 15 '17 at 23:17
  • $\begingroup$ Where are f and g coming from? $\endgroup$ – J. M.'s technical difficulties Oct 16 '17 at 3:02
  • $\begingroup$ f and g solutions from a finite element problem over a finite element mesh $\endgroup$ – 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[7]], AbsoluteThickness[1.5]},
  PlotLegends -> {h, hx}]


| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.