Message Boards Message Boards

0
|
2306 Views
|
2 Replies
|
1 Total Likes
View groups...
Share
Share this post:

Grad and ND of Interpolating function?

Posted 10 years ago

Hi Guys,

I would appreciate some pointers on numerical differentiation of interpolating functions in V10. What I really want to do is obtain Grad[f] where f is an interpolating function over R2. Using Grad did not work for me, so I tried ND, and it didn't either. I suspect it has to do with how and when it's evaluated. Is it possible to talk V10 into applying Grad, D, and/or ND to an interpolating function over Rn?

In[5]:= t = 
  Flatten[Table[{x, y, x^2 + y^2}, {x, -1, 1, .1}, {y, -1, 1, .1}], 1];

In[9]:= ft = Interpolation[t];

In[11]:= ND[ft[x, .5], x, .25]

Out[11]= ND[
 InterpolatingFunction[{{-1., 1.}, {-1., 1.}}, <>][x, 0.5], x, 0.25]
POSTED BY: David Keith
2 Replies
Posted 10 years ago

Thanks very much, Marco. It's great. Just what I needed.

grad[f_, {xx_, yy_}] := Grad[f[x, y], {x, y}] /. {x -> xx, y -> yy}
POSTED BY: David Keith

Hi,

what about this:

t = Flatten[Table[{x, y, x^2 + y^2}, {x, -1, 1, .1}, {y, -1, 1, .1}], 1];
ft = Interpolation[t];

Just test that it works:

Plot3D[ft[x, y], {x, -1, 1}, {y, -1, 1}]

enter image description here

Ok. Now plot the derivative

Plot[D[ft[x, .5], x] /. x -> z, {z, -1, 1}]

enter image description here

So

D[ft[x, .5], x] /. x -> 0.25

should do the trick. Similarly,

\!\(\*SubscriptBox[\(\[Del]\), \({x, y}\)]\(ft[x, y]\)\) /. {x -> 0.25, y -> 0.5}

looks alright. We can also define a new function

gradf[u_, v_] := \!\(\*SubscriptBox[\(\[Del]\), \({x, y}\)]\(ft[x, y]\)\) /. {x -> u, y -> v };

and then use

gradf[0.25, 0.5]

but I am sure that there is a more elegant way.

Cheers, Marco

POSTED BY: Marco Thiel
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract