Quantcast
Channel: Plotting with units: emits error and gives incorrect plot - Mathematica Stack Exchange
Viewing all articles
Browse latest Browse all 2

Plotting with units: emits error and gives incorrect plot

$
0
0

I've been trying to find some information on how to use Plot with a quantity that has units. I have a function, h[x_], that takes as input a value with units of centimeters and produces as output a value with units of Amperes per centimeter (I'd like it to output in Oersteds but that's a different question for a different time). I want to plot the value of h[x] as a fraction of the value of Hinf (a quantity with dimensions of Amperes per centimeter). What I am trying is

h[x_] := 4 Pi/10*Quantity[2, "Amperes"]*960/(Quantity[60.96, "Centimeters"])*(((Quantity[60.96, "Centimeters"]) + 2 x)/(2 Sqrt[(Quantity[2.54, "Centimeters"])^2 + (Quantity[60.96, "Centimeters"] + 2 x)^2]) + ((Quantity[60.96, "Centimeters"]) - 2 x)/(2 Sqrt[(Quantity[2.54, "Centimeters"])^2 + (Quantity[60.96, "Centimeters"] - 2 x)^2]))Hinf := 4 Pi/10*960/Quantity[60.96, "Centimeters"]*Quantity[2, "Amperes"]Plot[Evaluate[h[x]/Hinf], {x, Quantity[0, "Centimeters"], Quantity[30.48, "Centimeters"]}]

which returns an error message, along with a vastly incorrect plot (this should be the magnetic field intensity inside of a solenoid, but instead seems to be something completely different?).

I actually input the various quantities using the ctrl-= Wolfram Alpha interface, just in case that would help to know.

error message and plot

I have no idea what I did wrong here that's making Mathematica give me this mess instead of what I asked for, and I can't figure out how to interpret the error message. How can I get it to plot properly?

A bit of further information:

Evaluate[h[Quantity[0, "Centimeters"]]/Hinf]

does indeed output the correct value, and this does work for any value as the argument of h.


Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles



Latest Images