Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X
I am trying to use rnorm to create a vector of random numbers.
The vector should have (density) units of lb/ft^3. For some reason when I attempt to give the sigma and mu values units of lb/ft^3, the numbers come out incorrect and without the desired units. Where should I look to fix this?
Thanks,
Jason
That's because the default units in Mathcad are SI units. Your inputs (mu and sigma) are provided by you with units. Mathcad translates them internally to SI and then generates the list of random numbers. Unfortunately the random number generator is not designed to handle units, so it simply forgets them. You get a vector of unitles numbers
If you add the units you want to the output, you should see your familiar values, but the unit (lb/ft^) gets prepended with m^3/kg, to make sure they remain uniitless.
Because of the limitation in the random number generator, you should just generate the numbers you want (as in your second attempt) and multiply the result with lb/ft^3.
Success!
Luc
LucMeekes wrote:
That's because the default units in Mathcad are SI units. If you add the units you want to the output, you should see your familiar values.
Looks like it would not be that easy:
Werner
Unfortunately I can't read 3.1 files.
Is it something like this:
Werner
No Werner. I wouldn't do it that complicated. Just plain:
Luc
And the original part was like this:
And when I added the lb/ft^3 it turned into:
Because Prime counteracted with m^3/kg.
Ah, I see, thanks. So my first post applies.
Nevertheless rnorm should work correctly with units. For example I would expect an error if mu and sigma are of different dimensions and the output should have the same dimension as mu and sigma.
Werner
For example:
Too bad...
Mathcad 11 does a better job:
My Prime 3.0 can't read your P3.1 file (crazy enough) but I was able to duplicate the problem you describe.
The values are coverted to base units and used (and returned) without any unit. Clearly not as it should be and it looks like Prime is not unit aware to the degree we would like it to be.
Workaround could be to call rnorm without units and ad the desired unit manually.
If mu and sigma should be variables with units, you will have to divide by the proper unit when you call rnorm.
Regards, Werner
Werner,
Many thanks for this solution. This will move me forward. It is unfortunate that MathCad is in such a state that these bizarre work-around are required. Hopefully one day the product will be improved so that it is as intuitive to use as it should be.
Thanks again for your help.
Sincerely,
Jason Dugas
Many thanks for this solution.
You are welcome.
Hopefully one day the product will be improved so that it is as intuitive to use as it should be.
Hopefully one day Prime will be as advanced as Mathcad 14/15 used to be 10 years ago. 😞
No, what you demand will not work as expected in the old version either and concerning unit awareness Prime really has undergone some improvements. But there is so much missing and so many things are so much slower and more awkward to handle in Prime. Its a shame.
Werner
10 years ago....you're referring to Mathcad 12? (which turned out to be a bad idea). 13, 14 and 15 came later.
10 years ago the unsurpassed Mathcad 11 was around.
Luc