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

  • $\begingroup$ You're missing a couple of definitions? $\endgroup$
    – Feyre
    May 7, 2017 at 15:54
  • $\begingroup$ Since you are using quantities, look at the documentation for Quantity $\endgroup$
    – Bob Hanlon
    May 7, 2017 at 16:51
  • $\begingroup$ @Feyre Ahh, Sorry I didn't consider posting the entire code. v = 8434 m^3 Roh_h = 0.1785kg/m^3 Roh_0 = 1.225 kg/m^3 h_0 = 8434 n = 1.25 their actual values I suppose for the question arn't important, but they are defined. Sorry if it's unclear to anyone $\endgroup$ May 7, 2017 at 16:55
  • $\begingroup$ @BobHanlon I will have a read. and return if I don't manage to solve. thanks for the tips. $\endgroup$ May 7, 2017 at 16:58

2 Answers 2

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,
 Frame -> {{True, False}, {True, False}},
 AxesOrigin -> {0, 0},
 FrameLabel -> {"ml in kilograms", "z in kilometers"}]

enter image description here

  • $\begingroup$ 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! $\endgroup$ May 7, 2017 at 20:19


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


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.