2

I've been getting issues with plotting a function I've written to calculate the maximum height a floating body can float in a polytrope atmosphere dependant on a weight, here is the function;

X[ml_] := Power[(v Subscript[\[Rho], h] + 6000 kg + ml)/(
v Subscript[\[Rho], 0]), ((n - 1))^-1]

z[ml_] := -(X[ml] - 1) (n Subscript[h, 0])/(n - 1)

I would like to plot it, but I get an error that regardless of googling I can't seem to find an answer. The error message being:

In[207]:= Plot[z[ml], ml]

Out[207]= System`ProtoPlotDump`iPlot[Plot, \System`ProtoPlotDump`obj$53256, z[ml], ml]

I found, while googling, this link (Plotting discontinuous functions without spurious vertical segments) with close to the same error message. However, my function shouldn't be discontinuous in its entire range and I don't understand enough of mathematica to apply this example to mine.

I tried plotting the function again within a specific range (1m to 3000m) and this time the graph appears but not actual plot. (see image)

What is the error in my code? Or more accurately, how can I plot this function?

To clarify, my function requires values to be given in kg and returns values in m (metres). Like so

In[217]:= z[300 kg]

Out[217]= 28384.6 m 

(albeit the returned value seems a little high...but that is a different issue)

When trying set that range, mathematica just returns the function again.

In[216]:= Plot[z[ml], {ml, 1 kg, 3000 kg}]

Out[216]= Plot[z[ml], {ml, 1 kg, 3000 kg}]

Thank you for the help! Here is a screen shot of mathematica, I'm running version 11.enter image description here

DrMrstheMonarch
  • 2,971
  • 1
  • 10
  • 16

2 Answers2

3
const = {v -> Quantity[8434, "Meters"^3],
   Subscript[ρ, h] -> Quantity[0.1785, "Kilograms"/"Meters"^3],
   Subscript[ρ, 0] -> Quantity[1.225 , "Kilograms"/"Meters"^3],
   Subscript[h, 0] -> Quantity[8434, "Meters"],
   n -> 1.25};

Note that I made Subscript[h, 0] a quantity ("Meters") rather than the dimensionless constant provided.

X[ml_] := Power[(v Subscript[ρ, h] + Quantity[6000, "Kilograms"] + 
     ml)/(v Subscript[ρ, 0]), ((n - 1))^-1]

z[ml_] := -(X[ml] - 1) (n Subscript[h, 0])/(n - 1)

z[Quantity[300, "Kilograms"]] /. const

(*  Quantity[28432.1, "Meters"]  *)

Plot[z[Quantity[ml, "Kilograms"]] /. const, {ml, 1, 3000},
 Frame -> {{True, False}, {True, False}},
 AxesOrigin -> {0, 0},
 FrameLabel -> {"ml in kilograms", "z in meters"}]

enter image description here

Or to convert to kilometers

Plot[UnitConvert[z[Quantity[ml, "Kilograms"]] /. const, "Kilometers"], {ml, 1,
   3000},
 Frame -> {{True, False}, {True, False}},
 AxesOrigin -> {0, 0},
 FrameLabel -> {"ml in kilograms", "z in kilometers"}]

enter image description here

Bob Hanlon
  • 157,611
  • 7
  • 77
  • 198
  • Thank you very much! after reading about quantities I immediately tried to plot without my constants...which worked of course. Just after you posted this, I was in the process of trying to plot with quantities...which didn't work :D, Thanks again for the help! – DrMrstheMonarch May 07 '17 at 20:19
1

In:

v = 8434 ;
Subscript[\[Rho], h] = 0.1785  ;
Subscript[\[Rho], 0] = 1.225  ;
Subscript[h, 0] = 8434 ;
n = 1.25;
X[ml_] := 
 Power[(v Subscript[\[Rho], h] + 6000 + 
     ml)/(v Subscript[\[Rho], 0]), ((n - 1))^-1]
z[ml_] := -(X[ml] - 1) (n Subscript[h, 0])/(n - 1)

Plot[z[ml], {ml, 1 , 3000}]

Out: enter image description here

webcpu
  • 3,182
  • 12
  • 17