*To convert and simplify units in tables (was:LIterate programming with calc (help))@ 2022-11-27 19:19 Ypo2022-12-10 13:51 ` Ihor Radchenko 2022-12-12 9:08 ` To convert and simplify units in tables Fraga, Eric 0 siblings, 2 replies; 5+ messages in thread From: Ypo @ 2022-11-27 19:19 UTC (permalink / raw) To: Org-mode [-- Attachment #1: Type: text/plain, Size: 2656 bytes --] Hi I have found an alternative solution to this problem: > Is it possible to express in a calc block some basic operations with > variables and non-predefined units? > > > For example, if you wanted to build a code block that calculates how > much money costs > > a land with an Area of 300x300 m^2 at a price of 1 $/m^2. > > > Would it be something like this? > > #+begin_src calc > a = 300 m > b = 300 m > Area = a*b > cost = 1 ($/m^2) > A*c > > #+end_src > The alternative way I am trying is using an org-table. It is not literate programming, but it is a spreadsheet with units ;D | $ | a = 300 m | | $ | b = 300 m | | _ | Area | | | 90000 m^2 | | $ | cost = 1 USD/m^2 | | _ | Payment | | | 90000 USD | #+TBLFM: $Area=$a*$b::$Payment=$Area*$cost (Below "Area" cell it is the result of a*b, and below "Payment" cell it is the result of Area*cost) Now, in a more practical case, I have some problems with units: | $ | E = 2141404.05 kg/cm^2 | | $ | s_lim = 275 N/mm^2 | | $ | s_lim = 2800 kg/cm^2 | | $ | W = 10000 kg | | $ | l = 65 cm | | $ | I = 25166 cm^4 | | $ | Z = 1680 cm^3 | | _ | s | | | 386.90476 kg cm / cm^3 | | _ | cs | | | 7.2369231 kg cm^3 / (cm^2 kg cm) | #+TBLFM: $s=$W*$l/$Z::$cs=$s_lim/$s Below "cs" cell it appears 7.2... and this should be an adimensional number (no units). Is it possible to simplify those units? I have tried with: | $ | E = 2141404.05 kg/cm^2 | | $ | s_lim = 275 N/mm^2 | | $ | s_lim = 2800 kg/cm^2 | | $ | W = 10000 kg | | $ | l = 65 cm | | $ | I = 25166 cm^4 | | $ | Z = 1680 cm^3 | | _ | s | | | 386.90476 kg / cm^2 | | _ | cs | | | #ERROR | #+TBLFM: $s=uconvert($W*$l/$Z,kg / cm^2)::$cs=uconvert($s_lim/$s, ) where uconvert is defined as: (defmath uconvert (v u) "Convert value V to compatible unit U." (math-convert-units v u)) But no luck, "cs" result is an ERROR. Is it feasible to get a value for "cs" with no units? Best regards [-- Attachment #2: Type: text/html, Size: 4787 bytes --] ^ permalink raw reply [flat|nested] 5+ messages in thread

*Re: To convert and simplify units in tables (was:LIterate programming with calc (help))2022-11-27 19:19 To convert and simplify units in tables (was:LIterate programming with calc (help)) Ypo@ 2022-12-10 13:51 ` Ihor Radchenko2022-12-10 16:04 ` ypuntot 2022-12-12 9:08 ` To convert and simplify units in tables Fraga, Eric 1 sibling, 1 reply; 5+ messages in thread From: Ihor Radchenko @ 2022-12-10 13:51 UTC (permalink / raw) To: Ypo;+Cc:Org-mode Ypo <ypuntot@gmail.com> writes: > (defmath uconvert (v u) > "Convert value V to compatible unit U." > (math-convert-units v u)) > > > But no luck, "cs" result is an ERROR. Is it feasible to get a value for > "cs" with no units? Note that apart from Calc formula notation, you can use Elisp. That will avoid all the gotchas Calc has. -- Ihor Radchenko // yantar92, Org mode contributor, Learn more about Org mode at <https://orgmode.org/>. Support Org development at <https://liberapay.com/org-mode>, or support my work at <https://liberapay.com/yantar92> ^ permalink raw reply [flat|nested] 5+ messages in thread

*Re: To convert and simplify units in tables (was:LIterate programming with calc (help))2022-12-10 13:51 ` Ihor Radchenko@ 2022-12-10 16:04 ` ypuntot0 siblings, 0 replies; 5+ messages in thread From: ypuntot @ 2022-12-10 16:04 UTC (permalink / raw) To: Ihor Radchenko;+Cc:Org-mode Hi Ihor. I'm null at elisp. Could you please refer to me a simple example of math operation and unit simplification in elisp? Thanks :$ 10 dic 2022 14:51:39 Ihor Radchenko <yantar92@posteo.net>: > Ypo <ypuntot@gmail.com> writes: > >> (defmath uconvert (v u) >> "Convert value V to compatible unit U." >> (math-convert-units v u)) >> >> >> But no luck, "cs" result is an ERROR. Is it feasible to get a value for >> "cs" with no units? > > Note that apart from Calc formula notation, you can use Elisp. That will > avoid all the gotchas Calc has. > > -- > Ihor Radchenko // yantar92, > Org mode contributor, > Learn more about Org mode at <https://orgmode.org/>. > Support Org development at <https://liberapay.com/org-mode>, > or support my work at <https://liberapay.com/yantar92> ^ permalink raw reply [flat|nested] 5+ messages in thread

*Re: To convert and simplify units in tables2022-11-27 19:19 To convert and simplify units in tables (was:LIterate programming with calc (help)) Ypo 2022-12-10 13:51 ` Ihor Radchenko@ 2022-12-12 9:08 ` Fraga, Eric1 sibling, 0 replies; 5+ messages in thread From: Fraga, Eric @ 2022-12-12 9:08 UTC (permalink / raw) To: Ypo;+Cc:Org-mode On Sunday, 27 Nov 2022 at 20:19, Ypo wrote: > The alternative way I am trying is using an org-table. It is not > literate programming, but it is a spreadsheet with units ;D > [...] > Now, in a more practical case, I have some problems with units: > > | $ | E = 2141404.05 kg/cm^2 | > | $ | s_lim = 275 N/mm^2 | > | $ | s_lim = 2800 kg/cm^2 | > | $ | W = 10000 kg | > | $ | l = 65 cm | > | $ | I = 25166 cm^4 | > | $ | Z = 1680 cm^3 | > | _ | s | > | | 386.90476 kg cm / cm^3 | > | _ | cs | > | | 7.2369231 kg cm^3 / (cm^2 kg cm) | > > #+TBLFM: $s=$W*$l/$Z::$cs=$s_lim/$s org tables do have support for units, based on Emacs Calc. You need to add the "u" option to the formulas for this support. If I change your formulas to: #+TBLFM: $cs=$s_lim/$s;u::$s=$W*$l/$Z;u everything seems to work just fine. -- : Eric S Fraga, with org release_9.6-14-g53814a in Emacs 30.0.50 ^ permalink raw reply [flat|nested] 5+ messages in thread

*To convert and simplify units in tables (was:LIterate programming with calc (help))@ 2022-11-28 18:58 Ypo0 siblings, 0 replies; 5+ messages in thread From: Ypo @ 2022-11-28 18:58 UTC (permalink / raw) To: Org-mode [-- Attachment #1: Type: text/plain, Size: 465 bytes --] > #+TBLFM: $s=uconvert($W*$l/$Z,kg / cm^2)::$cs=uconvert($s_lim/$s, ) > > where uconvert is defined as: > > (defmath uconvert (v u) > "Convert value V to compatible unit U." > (math-convert-units v u)) > > > But no luck, "cs" result is an ERROR. Is it feasible to get a value > for "cs" with no units? > Ok, it is enough to add any unit to uconvert, for example: $cs=uconvert($s_lim/$s,m). That simplifies units in adimensional parameters. Best regards ;D [-- Attachment #2: Type: text/html, Size: 1090 bytes --] ^ permalink raw reply [flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-12-12 9:17 UTC | newest]Thread overview:5+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2022-11-27 19:19 To convert and simplify units in tables (was:LIterate programming with calc (help)) Ypo 2022-12-10 13:51 ` Ihor Radchenko 2022-12-10 16:04 ` ypuntot 2022-12-12 9:08 ` To convert and simplify units in tables Fraga, Eric 2022-11-28 18:58 To convert and simplify units in tables (was:LIterate programming with calc (help)) Ypo

Code repositories for project(s) associated with this public inbox https://git.savannah.gnu.org/cgit/emacs/org-mode.git This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).