Ask Your Question
1

Working with units

asked 2020-01-12 00:49:40 -0600

erikblue gravatar image

Hi,

I am just getting started with sage. I'm an electrical engineer. One thing that was really nice about Mathcad was letting me know if my units were messed up. I see there are electrical units types, like "units.electrical_potential.volt" but I'm struggling to see how to use it in a real application.

For example, a resistor, do I do something like this for 220 ohm resistor?

R = 220 * units.resistance.ohms

And what I'd really like to do is then define a voltage:

V = 1*units.electrical_potential.volt

And then be able to just go like this to get the current through the resistor:

V/R

Which would output something like this:

0.00455 * units.current.amp

Or better yet, just:

4.55mA

I don't mind building my own class to achieve this functionality. I also need to create my own units, for example noise spectral density such as V*sqrt(Hz).

Anyways, I really like what I see with Sage so far, I tried to use PTC Mathcad a while back and was pulling my hair out... Sage seems super intuitive and flexible, just being able to type things out in the notebook is great.

Thank you!

Erik

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
2

answered 2020-01-13 04:19:46 -0600

eric_g gravatar image

Do you know Pint?

As for any Python package, it should be easy to install it in SageMath by typing the following command in a terminal:

sage -pip install pint

NB: this requires SageMath 9.0 since the latest version of Pint works only with Python 3.

edit flag offensive delete link more

Comments

2

astropy also has a very powerful units and quantities package which took much of its original inspiration from Pint. Actually, lately they've been converging more and more again on shared functionality (thanks in part to recent updates to Numpy making propagation of units easier)--I wonder if one day it will be possible for them to converge, rather than maintaining separate projects. Though astropy.units does have some more advanced functionality specific to the astronomy community (though also useful for most any science).

Iguananaut gravatar imageIguananaut ( 2020-01-13 06:05:17 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2020-01-12 00:48:43 -0600

Seen: 29 times

Last updated: Jan 13