Message Boards Message Boards

0
|
8152 Views
|
7 Replies
|
4 Total Likes
View groups...
Share
Share this post:

[?] Avoid problem with Units Seconds vs. s?

Posted 7 years ago

This ist only my first simple steps to build a computation to dimension an upload service. Even the first steps are not easy. If i am evaluating this:

uploadtime[filesize_, bandwidth_] := (filesize / bandwidth)
uploadtime[UnitConvert[Quantity[12770776, "Bytes"], "Megabits"], 
 Quantity[2.4, "Megabits"/"Seconds"]]

I am getting this:

Quantity[42.5693, "Seconds"]

If I am evaluating this:

Convert[Month, Second]

I am getting this:

2628000 Second

If I am mulitplying both results I am getting:

Second (Quantity[52560000, ("Megabits")/("Seconds")])

What am I doing wrong?

POSTED BY: Oliver Scholz
7 Replies
Posted 7 years ago

The last evaluates to: Second (Quantity[52560000, ("Megabits")/("Seconds")]) Why is there a Megabits / Seconds and Second as an result. I would expect that Convert[Month, Second] should evaluate to something which is a number of Seconds.

POSTED BY: Oliver Scholz

You're mixing two packages, the built-in functionality and the one from (the very old) Units. Try not to use the Units package any more, everything is now built-in, use the functions:

UnitConvert  (*also to 'simplify' *)
Quantity
QuantityMagnitude
POSTED BY: Sander Huisman
Posted 7 years ago
Convert[Month, Second]
Quantity[20, "Megabits"/"Seconds"]
%1 * %2
POSTED BY: Oliver Scholz

Welcome to Wolfram Community! Please make sure you know the rules and how to format code properly, which you can find here: https://wolfr.am/READ-1ST Not formatting your code can make it unusable to other members. Please respect forum rules.

POSTED BY: Moderation Team
Posted 7 years ago
Needs["Units`"]
Convert[Month, Second]
Out[1] 2628000 Second
Quantity[20, "Megabits"/"Seconds"] * Convert[Month, Second]
Out[2] Second (Quantity[52560000, ("Megabits")/("Seconds")])

I expected to have only one unit of Seconds either Second or s and not both of them

POSTED BY: Oliver Scholz

Can you try formatting your code? It's hard to read and I'm not sure I am understanding what you are doing.

You can format your code by highlighting and clicking the "code sample" button. The code sample button is the first button above the text input field:

enter image description here

It looks like you are typing out "Second" by itself instead of typing Quantity[2628000, "Seconds"].

POSTED BY: Sean Clarke

First, you wrote this function:

uploadtime[filesize_, bandwidth_] := (filesize/bandwidth);

You can use this function with Quantities. For example,

uploadtime[
    Quantity[12770776, "Bytes"], 
    Quantity[2.4, "Megabits"/"Seconds"]]

Quantity[42.5693, "Seconds"]

As you can see, there is no need to call UnitConvert. The division operation handles unit conversion automatically.

You mentioned that you also evaluated:

 UnitConvert["Month", "Second"]

 Quantity[2628000, "Seconds"]

Is this correct?

Can you type-out what calculation seems to not be working for you?

POSTED BY: Sean Clarke
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract