cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

The community will undergo maintenance on October 16th at 10:00 PM PDT and will be unavailable for up to one hour.

How to create inverse units [e.g. /dBm(x)] in Mathcad Prime?

pwanis
1-Newbie

How to create inverse units [e.g. /dBm(x)] in Mathcad Prime?

I'd like to implement some form of decibels in Mathcad. I've found a few nice references:

Mathcad Example Using Decibels | Math Encounters Blog

https://books.google.com/books?id=DfVVkGnzIJAC&printsec=frontcover#v=onepage&q=inverse%20function&f=false

In both of these examples they are creating a forward function dB(x), which works just fine, but also an "inverse function" /dB(x). No matter how I try I cannot get Mathcad Prime to create something that looks like that inverse function. (The CTRL+SHIFT+K approach recommended in the second link doesn't work in Prime.) The closest I've gotten is when I got the Mathcad error message "Unknown error: no_inverse_declared."

Is there any way to create an "inverse function" in Prime?

ACCEPTED SOLUTION

Accepted Solutions
RichardJ
19-Tanzanite
(To:pwanis)

Here's a Mathcad 15 worksheet that shows how to use dB. I've posted this before (more than once, I think; see here for the original post in a discussion, or argument, about dB: Solved: Re: Working with dB (decibels) - PTC Community). I converted it to Prime, and it doesn't work; it just throws the error you have already seen. So I think you are out of luck. Yet another deficiency in Prime.

View solution in original post

14 REPLIES 14

One general remark.

We have use dB, pH etc. only in manual calculation. We does not need dB, pH etc. in computer calculation.

And partially 2 pictures from the book Thermal Engineering studies with Excel, Mathcad and Internet

Fig-2-10.png

Fig-2-11.png

Yes I agree that dB shouldn't be needed for automated calculation, since dB is a shortcut created for easier (human) calculation. But in RF and sonar all of the standard formulas are centered around dB, dBm, dB re 1uPa, etc so it would be nice to be able to use those units within Mathcad.

RichardJ
19-Tanzanite
(To:pwanis)

Here's a Mathcad 15 worksheet that shows how to use dB. I've posted this before (more than once, I think; see here for the original post in a discussion, or argument, about dB: Solved: Re: Working with dB (decibels) - PTC Community). I converted it to Prime, and it doesn't work; it just throws the error you have already seen. So I think you are out of luck. Yet another deficiency in Prime.

JeffH1
15-Moonstone
(To:pwanis)

The Prime shortcut for special characters is different than Mathcad 15.0 (Ctrl-Shift-K).  First, type a double quote (which in 15 gave you text, but not in prime).

     ""

In between the double quotes, type /dB

     "/dB"

Now delete either of the quote marks and follow this variable with a parenthesis to make it a function

     /dB( x )

Press : and define the function.

In Mathcad 15, you could make this a postfix operator, but these aren't implemented in Prime yet.

pwanis
1-Newbie
(To:JeffH1)

The good news: this trick (using quotes) worked, and I could enter the formula exactly as you said.

The bad news: mathcad still doesn't appear to be treating this as an inverse function; even when I do declare /dB(x) I still get the error no_inverse_declared. Unfortunately I think Richard Jackson hit the nail on the head.

StuartBruff
23-Emerald III
(To:pwanis)

Has this problem been fixed yet?  I can find no reference in Help to how to implement an inverse (unit) function.   

 

To move away from discussion about the merits or otherwise of displaying dimensionless units, I have another example - conversion of numbers between bases.  I can write a 'unit' function that displays a number as, say, a binary, octal or hex number (well, string, actually).  What I'd like to do is use the same name to go from a string to a decimal number (a genuine number, this time).

 

2020 05 16 B.png

 

Cheers,

 

Stuart

LucMeekes
23-Emerald III
(To:StuartBruff)

@StuartBruff:

Stuart,

just out of curiosity, I was wondering what your bin/oct/hex conversion functions look like.

 

Luc

 

StuartBruff
23-Emerald III
(To:LucMeekes)


@LucMeekes wrote:

@StuartBruff:

Stuart,

just out of curiosity, I was wondering what your bin/oct/hex conversion functions look like.

 

Luc


Nothing special, Luc.

 

Some general-purpose string functions:

 

2020 05 28 C.png

 

Integer to Base conversion functions (number to string😞

2020 05 28 B.png

Base to Integer conversion functions (string to number😞

2020 05 28 A.png

 

I've got another version that works better with str2num ... I'll throw some documentation around it and, hopefully, post it later on today.   It's a bit "ragged" though, as it's in development, and uses some vector and string functions that are stepping stones to a more general, Mathcad-oriented, array handling capability.

 

Cheers,

 

Stuart

LucMeekes
23-Emerald III
(To:StuartBruff)

Admittedly your base2num function handles all(?) bases, but did you know that Prime handles a few out of the box:

LucMeekes_4-1590669611971.png

LucMeekes_0-1590669347101.png

LucMeekes_1-1590669391730.png

You MUST precede or start the number with a numerical digit (0...9):

LucMeekes_2-1590669414762.png

LucMeekes_3-1590669458940.png

Attached is my implementation of similar functions (Prime 4)

 

Luc

StuartBruff
23-Emerald III
(To:LucMeekes)


@LucMeekes wrote:

Admittedly your base2num function handles all(?) bases, but did you know that Prime handles a few out of the box:

LucMeekes_4-1590669611971.png

LucMeekes_0-1590669347101.png

LucMeekes_1-1590669391730.png

You MUST precede the number with a numerical digit (0...9):

LucMeekes_2-1590669414762.png

LucMeekes_3-1590669458940.png

Attached is my implementation of similar functions (Prime 4)

 

Luc


Yes, I did know, thanks, Luc.   That's what I was referring to when I said: "I've got another version that works better with str2num".   I extended str2num to cope with duodecimal numbers (*) and general bases, the latter being identified by the suffix "bnnn" where nnn is the base (in base 10), and I've also dropped the requirement to have a leading zero.  I also amended num2str to work hand-in-hand with str2num by adding a base argument to it - it's a shame we mere users can't define functions with optional arguments.   bin, oct, hex, and duo are specialized functions that perform bidirectional conversion, and accept strings with or without the base suffix.

 

2020 05 28 D.png

 

As I said, it's still in development and I'm sure there's a better way to do it.  I'll look at your worksheet and see what I can steal ... 😈

 

Cheers,

 

Stuart

 

(*)  Now that we're steaming ahead with Brexit, I imagine it won't be long before somebody decides to resurrect the Olde Ways and "bring back our duodecimal-vigesimal monetary system of pounds, shillings, and pence (real pennies, a dozen to the shilling, none of this pandering to the French Europeans and their decimal ways.  Hanging's too good for them!)".  I'm just getting ahead of the game.

 

(!@%!# (please imagine the preceding text string is shorthand for impolite words in Russian)). My laptop just expired on me, so I've had to switch to my iMac to complete this response ... I guess I'll have to defer looking at your worksheet until I get my PC laptop back up and running. 

StuartBruff
23-Emerald III
(To:StuartBruff)

... my laptop has an issue with its PSU connection overheating and failing to charge, so I guess I'm going to be digging out the soldering iron at some point.   In the meantime, I'm on the backup laptop with its low res screen.

 

Here's my slightly tidied-up worksheet.   I'm still not happy with the conversion functions, but I've got other things vying for my attention, so they'll have to do.   Our approaches seem to be similar in strategy but different in tactics.

 

Leading zeros aren't necessary and I've extended str2num to handles arbitrary bases (up to 35).

 

2020 05 29 A.png

 

2020 05 29 B.png

2020 05 29 C.png

 

2020 05 29 D.png

Cheers,

 

Stuart

Fred_Kohlhepp
23-Emerald I
(To:pwanis)

You can do this (see Prime 4 Express example).  It's tedious, but if you really need it:

FredKohlhepp_0-1589719857160.png

 

Thanks, Fred. I plan to check it out tomorrow.

Cheers,

Stuart
StuartBruff
23-Emerald III
(To:StuartBruff)

Sorry for the delay in replying, Fred ... I got sidetracked.

 

I'm afraid that your suggestion doesn't do what I want, which is to define an inverse function that can be used in a unit placeholder.  I get that pesky 'inverse function' error.

 

I can't access my M15 files (only got Express), but ISTR that even in m15 I had to "cheat" and hack a units XML(?) file to get such f-invf pairs to work properly.   

 

Does anybody know if PTC has any plans to allow users to define their own unit function pairs?

 

Cheers,

 

Stuart

Announcements

Top Tags