Last active
July 17, 2023 20:54
-
-
Save juandesant/7b7781345e7d4609edde785da8e08995 to your computer and use it in GitHub Desktop.
Astropy Units — Volume
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"nbformat": 4, | |
"nbformat_minor": 0, | |
"metadata": { | |
"colab": { | |
"name": "Untitled0.ipynb", | |
"provenance": [], | |
"collapsed_sections": [], | |
"authorship_tag": "ABX9TyNTBSZJAD3V8Sdh/cJ/jB/f", | |
"include_colab_link": true | |
}, | |
"kernelspec": { | |
"name": "python3", | |
"display_name": "Python 3" | |
}, | |
"language_info": { | |
"name": "python" | |
} | |
}, | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "view-in-github", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"<a href=\"https://colab.research.google.com/gist/juandesant/7b7781345e7d4609edde785da8e08995/untitled0.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "GP9HvCqUlGVB" | |
}, | |
"source": [ | |
"# Cálculos de volúmenes\n", | |
"\n", | |
"Vamos a utilizar `astropy` para el cálculo de unidades." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "KZ62OWExlBgE" | |
}, | |
"source": [ | |
"from astropy import units as u" | |
], | |
"execution_count": 1, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "QB8x7z_alEBA", | |
"outputId": "34da2751-fc3e-4a29-a484-7164acdc4dfa" | |
}, | |
"source": [ | |
"a = 50*u.m\n", | |
"b = 1*u.m\n", | |
"c = 1*u.m\n", | |
"(a,b,c)" | |
], | |
"execution_count": 2, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/plain": [ | |
"(<Quantity 50. m>, <Quantity 1. m>, <Quantity 1. m>)" | |
] | |
}, | |
"metadata": {}, | |
"execution_count": 2 | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 37 | |
}, | |
"id": "bRmZFLFnm8In", | |
"outputId": "a5238985-b1f4-407b-8e34-4e1b177c5dd5" | |
}, | |
"source": [ | |
"V = a*b*c\n", | |
"V.to(u.m**3)" | |
], | |
"execution_count": 3, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/latex": "$50 \\; \\mathrm{m^{3}}$", | |
"text/plain": [ | |
"<Quantity 50. m3>" | |
] | |
}, | |
"metadata": {}, | |
"execution_count": 3 | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 37 | |
}, | |
"id": "xPDediBFlZc3", | |
"outputId": "edf5d4b1-7a6a-4fc2-965b-dbc41e6fa5cc" | |
}, | |
"source": [ | |
"a = 50*u.m\n", | |
"b = 50*u.m\n", | |
"c = 50*u.m\n", | |
"V = a*b*c\n", | |
"V.to(u.m**3)" | |
], | |
"execution_count": 4, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/latex": "$125000 \\; \\mathrm{m^{3}}$", | |
"text/plain": [ | |
"<Quantity 125000. m3>" | |
] | |
}, | |
"metadata": {}, | |
"execution_count": 4 | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "_QfZaJfxljYK", | |
"outputId": "75603cd9-ff7b-4124-b0b6-9bcb3b4ca098" | |
}, | |
"source": [ | |
"a = pow(50,1/3)*u.m # o lo que es lo mismo, a es la raíz cúbica de 50\n", | |
"b = a # lados b = c\n", | |
"c = a # o sea, un cubo de lado 50^{1/3}, o ∛50 m.\n", | |
"(a,b,c)" | |
], | |
"execution_count": 5, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/plain": [ | |
"(<Quantity 3.6840315 m>, <Quantity 3.6840315 m>, <Quantity 3.6840315 m>)" | |
] | |
}, | |
"metadata": {}, | |
"execution_count": 5 | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 37 | |
}, | |
"id": "xUil8AVQlqEt", | |
"outputId": "906cfdc6-f800-45e7-fde3-c4ac25b2608d" | |
}, | |
"source": [ | |
"V=a*b*c\n", | |
"V.to(u.m**3)" | |
], | |
"execution_count": 6, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/latex": "$50 \\; \\mathrm{m^{3}}$", | |
"text/plain": [ | |
"<Quantity 50. m3>" | |
] | |
}, | |
"metadata": {}, | |
"execution_count": 6 | |
} | |
] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment