Unit Step and incorrect amplitude

ClearAll["Global*"] speed = 10 Quantity[1, ("Miles")/("Hours")] ;(*Speed of Car *) period = 10 Quantity[1, "Feet"];(* Period of peaks*) ampl = Quantity[.3, "Feet"] ;(*Half peak Amplitude*) ampl Subscript[\[Omega], b] = \!\(TraditionalForm\
*FractionBox[2\ \[Pi]\ speed, period]);
yy[t_] :=
ampl*Sin[(2 [Pi] speed t)/( 2 period)]^11 UnitStep[t/
Quantity[1, “Seconds”]] -
ampl Sin[(2 [Pi] speed t)/( 2 period)]^11 UnitStep[
t/Quantity[1, “Seconds”] - 4]; Plot[
Evaluate[yy[t]], {t, 0 Quantity[0, “Seconds”],
4.5 Quantity[1, “Seconds”]}, PlotTheme → “Web”,
FrameLabel → Automatic]

Why is the Plotted amplitude not .3 ft (if ampl = .3 ft)?

am I missing something with the units ? or UnitStep function ?

Kind regards,

John

John,

I’m not sure whether you’re expecting the actual amplitude to be .3 or whether you’re concerned that the plot looks cut off. If the latter, you can control this with the PlotRange option.

But for the former, I’m not really sure what is expected to happen when you apply Sin to a Quantity (try doing a simple plot of a Sin function ranging over a Quantity, and notice you don’t get any visible plot). On top of that, you have two length units and two time units and no usage of UnitConvert. Maybe you’re expecting that arithmetic with Quantities does automatic unit conversion, but if even if it did, your code would be a lot easier to understand and maintain if you explicitly used UnitConvert and QuantityMagnitude anyway. For what it’s worth, when I stripped out all of the quantities (and converted them), the amplitude was indeed 0.3.

speed = 10Quantity[1, “Miles”/“Hours”];
period = 10
Quantity[1, “Feet”];
ampl = Quantity[0.3, “Feet”];
w = (2Pispeed)/period;
yy[t_] := amplSin[wt]
Plot[Evaluate[yy[t]], {t, 0Quantity[1"Seconds"], 5Quantity[1"Seconds"]}, PlotTheme → “Web”, FrameLabel → Automatic]

Per Eric’s recommendation I have simplified the problem a bit… (thanks Eric)

Shouldn’t I expect the amplitude to be .3 ft ? (I was under the impression that in 10.3 Unit conversion was automatically applied–is this not the case ?)

Regards,

John

John,

In your yy function, if you use QuantityMagnitude[ampl] instead of just ampl you will get the expected amplitude. While I don’t really understand what’s going on in your original example, I still would suggest that you make your unit conversions and magnitude extractions more explicit. This would also allow you to parameterize your function for specific units, rather than just forcing it to Feet and Seconds.