Hello! In qalc I can do calculations using measuring units like this:

> 5 W * 3 s

  (5 watts) × (3 seconds) = 15 J

I’d like to be able to do something similar also in GNU Octave. I think the symbolic library could be a place to look at, but I found nothing “already done”. Do any of you know of a way to achieve this functionality?

    • tubbadu@lemmy.kde.socialOP
      link
      fedilink
      arrow-up
      3
      ·
      7 months ago

      It looks interesting, but more focused on conversions than actual operations it seems:

      octave:37> a.value = 100
      a =
      
        scalar structure containing the fields:
      
          value = 100
          unit = W
      
      octave:38> a.unit = 'W'
      a =
      
        scalar structure containing the fields:
      
          value = 100
          unit = W
      
      octave:39> b.value = 3
      b =
      
        scalar structure containing the fields:
      
          value = 3
          unit = s
      
      octave:40> b.unit = 's'
      b =
      
        scalar structure containing the fields:
      
          value = 3
          unit = s
      
      octave:41> a*b
      error: binary operator '*' not implemented for 'scalar struct' by 'scalar struct' operations
      
        • tubbadu@lemmy.kde.socialOP
          link
          fedilink
          arrow-up
          2
          ·
          7 months ago

          I downloaded it and tried to run it, but it gets stuck in a loop and I don’t know how it could be fixed:

          error: max_recursion_depth exceeded
          error: called from
              baseUnitSystem
              <unknown>
          

          it seems the problem is in the line

          coreUnits = buildCoreUnits(u.baseUnitSystem);
          

          in the file u.m, I think because u.baseUnitSystem tries to “call itself”. I don’t know what this should be supposed to do, and have no idea on how to possibly fix it :(

      • tubbadu@lemmy.kde.socialOP
        link
        fedilink
        arrow-up
        2
        ·
        7 months ago

        automatically no, but perhaps there’s a way to replace it. If there’s a way to check if a variable is “divisible by another symbolic one” then it would be not so hard to implement this behavior