What's the proper syntax to plot Interpolation functions defined over Quantities?

points = {{0, 0}, {1, 1}, {2, 3}, {3, 4}, {4, 3}, {5, 0}};

Change domain to Quantities:

points2 = points // Map[Replace[{x_, y_} :> {Quantity[x, "Days"], y}]];


ifun2 = Interpolation[points2];

This works:

ifun[Quantity[2.5, "Days"]]


But where's the plot:

 Plot[ifun2[x], {x, Quantity[0, "Days"], Quantity[5, "Days"]}]

(* empty *)

Yet this works:

 Plot[2 x, {x, Quantity[0, "Days"], Quantity[5, "Days"]}]

Oddly given this non-interpolated function over Quantities:

f[x_] := 2*Quantity[x, "Days"]

This works too, ie, argument x is already a Quantity:

 Plot[f[x], {x, Quantity[0, "Days"], Quantity[5, "Days"]}]
  • $\begingroup$ I would use ListPlot@Table[ifun2[x], {x, Quantity[0, "Days"], Quantity[5, "Days"]}] $\endgroup$ – eldo Aug 9 '17 at 22:58
  • 2
    $\begingroup$ Here's a start for an answer: ifun[QuantityMagnitude@x], since you're not interpolating over Quantity object but numbers. Alternatively, you can interpolate over Quantity[.., "Days"] (change points), but there is either a bug or poor design choice in the way Plot deals/strips Quantity from the input. You can do Plot[ifun3[Quantity[x, "Days"]], {x, 0, 5}]. Neither quite gets what I think you're after, which seems unreachable to me right now. $\endgroup$ – Michael E2 Aug 9 '17 at 23:15
  • $\begingroup$ @MichaelE2, by your suggestion, there is no point in using Quantities, which is the motivation of the question. $\endgroup$ – alancalvitti Aug 10 '17 at 3:05
  • $\begingroup$ Yes, that is my tentative conclusion. Or rather, I might say that it seems to me that for your use-case, Quantity has not been robustly implemented. IMO, your expectation that it would work is reasonable, and you should consider reporting it to WRI. $\endgroup$ – Michael E2 Aug 10 '17 at 3:37
  • $\begingroup$ @MichaelE2, wil do that, thanks. $\endgroup$ – alancalvitti Aug 10 '17 at 4:32

Your Answer

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

Browse other questions tagged or ask your own question.