Hi,
I’m trying to plot a function which takes quantities as inputs, but the resulting plot is either empty or completely wrong. Here is code that quickly shows the issue I’m having:
a = Quantity[0, "AngularDegrees"];
b = Quantity[90, "AngularDegrees"];
Plot[Sin[x], {x, a, b}]
I realize that if I instead do:
Plot[Sin[Quantity[x,"AngularDegrees"]],{x,0,90}]
that it works fine, so the issue seems to be in the range function (what is the list {x,xmin,xmax} called?). The problem is that I have functions which take multiple values, each with units, and where the ranges are all defined using constants or other functions, so I’d prefer to not write wrappers to rip off the units in order to make the range, and then put them back in when I call the function.
This seems like a bug to me. Am I missing something? Is there some general work-around for this? Some way of making a range using Quantities?
Thanks in advance for any help that you can offer.
I ran your code in Mathematica 12.0 and it seems to work just fine, what version of the Wolfram Language are you running your code on? Here is the output of your code.
One simple and a less technical workaround that I recommend you is to just update Mathematica. If you are not working on a huge scale project, I believe you won’t have difficulties with code incompatibility. If you can’t update to the newest version, please, describe the errors with screenshots.
Looking forward to helping you to figure out this problem.
Ah! I see! The first doesn’t obey that logic, because it understands that the x-axis range is from 0° to 90°, and not for plotting the points for the range between a and b.
A simple solution for that is plotting using ListLinePlot[] with Range[] and the two quantity ranges.
Thanks for another quick response. I wasn’t familiar with the ListLinePlot function so it is good that I can use that to work around this bug.
I don’t understand your comment about Plot “understanding” that the x-range is from 0 to 90 degrees. It isn’t plotting it that way – whether I choose to use:
So I’m pretty sure that Mathematica has a bug that it doesn’t understand Quantities (treat them properly) in the notation {x,xstart,xend} in the Plot function. Though, again, if I’m missing something important here please let me know.
Here is the code that I wrote based on that. Please note that I’ve only been using Mathematica a few days so it is entirely possible/likely that I’ve made some stupid mistakes. But it seems to work: