Re: Simplifying Units in Ezunits Package

serge de marre <[email protected]> Thu, 7 May 2026 23:20:23 +0200
Newsgroups gmane.comp.mathematics.maxima.general
Message-ID <CAON_BKzkP=ec-ndOxAyzvQd6C-w=y3PfjLgND_20qQ24+oqz2g@mail.gmail.com>
Should be
(%o16) 1000/101 `kHz;


On Thu, May 7, 2026 at 11:18 PM serge de marre <[email protected]> wrote:

> Hello Mateusz,
>
> I talked with Claude about this (and gave it access to a Maxima
> environment so that it could experiment and look up documentation instead
> of working from "memory") and it came up with this helper function:
> to_si(expr) :=
>    if mapatom(expr) then expr
>    else if op(expr) = "`" then expr `` fundamental_units(expr)
>    else map(to_si, expr);
>
> What it does is walk the expression tree, and it transforms any node that
> has units into an expression with the fundamental units for that expression.
> You have to apply this before trying to change to the units of your choice
> with ``
> So, looking at your examples, you could do the following:
> (%i16) to_si(%o5)``kHz;
> (%o16) 1000/101 `Hz;
>
> For your second example, you could do this:
> (%i17) to_si(f);
> (%o17) -((5000000*%i)/(9*(2000-(5000000*%i)/(9*%pi))*%pi))
> (%i18) ratsimp(%);
> (%o18) -((2500*%i)/(9*%pi-2500*%i))
>
> I hope it's useful.
>
> Kind regards,
> Serge
>
>
> On Thu, May 7, 2026 at 1:07 PM Mateusz M. <[email protected]> wrote:
>
>> Hello everyone
>>
>> I am very impressed with the capabilities of Maxima with the ezunits
>> package when it comes to practical engineering tasks. However, I still
>> encounter certain problems that I am unable to solve satisfactorily on my
>> own.
>> Please take a look:
>>
>> (%i4)   C_2: 10 `nF;
>>         C_1: 100 `pF;
>>         R_1: 10 `kOhm;
>>
>> (C_2)   10 ` nF
>> (C_1)   100 ` pF
>> (R_1)   10 ` kOhm
>>
>> Function fundamental_units returns proper unit value, but Maxima can't
>> simplify the fraction using ``.
>>
>> (%i7)   1/(R_1*(C_2 + C_1));
>>         fundamental_units(%);
>>         1/(R_1*(C_2 + C_1)) ``%;
>>
>> (%o5)   (1/10 ` 1/kOhm)/(100 ` pF+10 ` nF)
>> (%o6)   1/s
>> (%o7)   (1/10 ` 1/kOhm)/(100 ` pF+10 ` nF) `` 1/s
>>
>> I can solve this using some manipulations: force denominator to be
>> converted first or use subst to convert capacitance units to be the same:
>>
>> (%i10)  1/(R_1*(C_2 + C_1)) `` kHz;
>>         1/((R_1*(C_2 + C_1)) ``s) `` kHz;
>>         subst(nF = 1000 * pF, 1/(R_1*(C_2 + C_1))) ``kHz;
>>
>> (%o8)   (1/10 ` 1/kOhm)/(100 ` pF+10 ` nF) `` kHz
>> (%o9)   1000/101 ` kHz
>> (%o10)  1000/101 ` kHz
>>
>> The problem is that these aren't very versatile and clean solutions, and
>> this example is very simple.
>>
>> Here is another one I have a problem with:
>>
>> (%i15)  H(s, C, R_1, R_2) := (1/(s * C)) / (R_1 + R_2 + 1/(s * C));
>>     H(s, 18`nF, 1`kOhm, 1`kOhm);
>>     f: dimensionally(subst(%i*2*%pi*50`Hz, s, %));
>>     fundamental_units(f);
>>     f ``%;
>>
>> (%o11)  H(s,C,R_1,R_2):=(1/(s*C))/(R_1+R_2+1/(s*C))
>> (%o12)  (s^(-1)/18 ` 1/nF)/(s^(-1)/18 ` 1/nF+2 ` kOhm)
>> (f)     (-(%i/(1800*%pi)) ` 1/(Hz*nF))/(-(%i/(1800*%pi)) ` 1/(Hz*nF)+2 `
>> kOhm)
>> (%o14)  1
>> (%o15)  (-(%i/(1800*%pi)) ` 1/(Hz*nF))/(-(%i/(1800*%pi)) ` 1/(Hz*nF)+2 `
>> kOhm) `` 1
>>
>> Is there perhaps a simple and universal way to simplify units like in
>> MathCad or other engineering tools? I would appreciate any help.
>>
>> Best regards,
>> Mateusz Mróz
>> _______________________________________________
>> Maxima-discuss mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/maxima-discuss
>>
>

_______________________________________________
Maxima-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/maxima-discuss