MATLAB Answers

Interpolating n-dimensional functions

10 ビュー (過去 30 日間)
J Callahan
J Callahan 2020 年 7 月 4 日
コメント済み: J Callahan 2020 年 7 月 12 日 13:41
I have a function which takes six variables and gives a single numerical value, newfn(a,b,c,d,e,f,), although most will only take a small range of values, and want to create a grid where I vary these variables and then be able to interpolate values between the grid. As I understand it I need to make the grid for reference data first, for the sake of quick computation say it is something like:
then find the reference values:
then suppose our grid of values to interpolate to is given by
Then I thought I'd be able to use griddatan like this:
but this isn't working, so I'm going badly wrong somewhere?

  0 件のコメント

Sign in to comment.


John D'Errico
John D'Errico 2020 年 7 月 4 日
First, IF you have a complete gridded lattice, then you don't want to use griddatan. That is DEFINITELY a BAD idea. Why? Because griddatan will try to tessellate that domain. It thinks you have a scattered set of data, and has no idea how things are related. The result would be very slow at best, and for no good reason. Actually, tit would be a good reason - you want to use the wrong tool in griddatan.
The actual failure of griddatan there is because you are calling it incorrectly. But since this is the wrong tool to use in the first place, just use the correct tool.
Instead, you need to use a tool like griddedInterpolant, or interpn. Either will work, although if you wish to use interpn, then you need to create the grid using meshgrid, not ndgrid. Since you have used ndgrid there, then use griddedInterpolant.

  3 件のコメント

J Callahan
J Callahan 2020 年 7 月 6 日
Thanks, that absolutely did what I wanted it to.
Am I right in thinking I wouldn't be able to use meshgrid since there are more than 3 dimensions?
John D'Errico
John D'Errico 2020 年 7 月 12 日 13:29
No. meshgrid works in as many dimensions as you want. It has the somewhat odd behavior that it interchanges the first and second dimensions still, as consistent with how meshgrid works in 2-d. You really don't need to worry about that though.
But interpn presumes the use of meshgrid generated arrays, even in a higher number of dimensions.
griddedInterpolant requires the ndgrid variation. Just use the one needed for the tool you will be using, and all will be good.
J Callahan
J Callahan 2020 年 7 月 12 日 13:41
Thanks very much!

Sign in to comment.

その他の回答 (0 件)

Translated by