Message Boards Message Boards

0
|
2197 Views
|
9 Replies
|
3 Total Likes
View groups...
Share
Share this post:

Use Interpolation with a Dataset

Posted 10 months ago

Suppose I have the following dataset:

dataset = Dataset[{
   <|"t" -> -3, "v" -> 9|>,
   <|"t" -> -2, "v" -> 4|>,
   <|"t" -> -1, "v" -> 1|>,
   <|"t" -> 0, "v" -> 0|>,
   <|"t" -> 1, "v" -> 1|>,
   <|"t" -> 2, "v" -> 4|>,
   <|"t" -> 3, "v" -> 9|>
   }]

I want to find an interpolation polynom using Interpolation.

What I do now is

Interpolation[
 Thread[{
   dataset[All, "t"] // Normal,
   dataset[All, "v"] // Normal
   }]
 ]

But I am sure there is a more concise way to do it.

EDIT:

What if my data set is a 3 columns one, and I want to find a t vs v or a t vs u interpolation? For example,

dataset=Dataset[{
<|"t" -> -3, "v" -> 0, "u" -> -5|>,
<|"t" -> -2, "v" -> 3, "u" -> 8|>,
<|"t" -> -1, "v" -> -3, "u" -> -9|>,
<|"t" -> 0, "v" -> -3, "u" -> 4|>,
<|"t" -> 1, "v" -> -8, "u" -> -10|>,
<|"t" -> 2, "v" -> 2, "u" -> 8|>,
<|"t" -> 3, "v" -> 4, "u" -> -10|>
}]

I tried Interpolation[dataset[All, {"t", "v"}]//Normal] is not good. Any suggestion?

POSTED BY: Ehud Behar
9 Replies

Here is another way:

dataset[Values /* Interpolation]
POSTED BY: Carl Verdon
Posted 10 months ago

Nice. What if I want to use InterpolationOrder->2 and not the default value?

POSTED BY: Ehud Behar
dataset[Values /* (Interpolation[#, InterpolationOrder -> 2] &) ]

Be sure to enclose the Interpolation pure function with parentheses.

POSTED BY: Carl Verdon
Posted 10 months ago
Interpolation[Normal[Values[dataset]]]
POSTED BY: Eric Rimbey
Posted 10 months ago

Well done!

POSTED BY: Ehud Behar
Posted 10 months ago

I edited the original question. Please, if you could have a look.

POSTED BY: Ehud Behar
Posted 10 months ago

Just do the same thing.

POSTED BY: Eric Rimbey
Posted 10 months ago

Sorry. I need to specify the columns (whether it is t and v or t and u). How to do it with your approach?

POSTED BY: Ehud Behar
Posted 10 months ago

Okay, I guess I got my questions mixed up. You've asked a couple of related questions dealing with Dataset. In this one, Plot specific named columns of a dataset , I showed you how to extract two columns. In this one that we're now working on, I've already showed you how to turn dataset columns into a list of pairs that can be fed to Interpolation. If you just put it all together, you can get what you want.

(* From this current thread... *)
Normal[Values[dataset]]
(* ...gives you a list of pairs*)

(* From that other thread... *)
dataset[All, {"t", "v"}]
(* ... extracts columns from a Dataset  *)

(* So, just put it all together *)
Interpolation[Normal[Values[dataset[All, {"t", "v"}]]]]
POSTED BY: Eric Rimbey
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