Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Inverse Modulus operator (Mod)

703 views
Skip to first unread message

Mike Malkum

unread,
May 18, 2009, 9:07:01 PM5/18/09
to
Hello everyone,
Is there any way to calculate the inverse of the mod operator in Matlab or simulink?

I appreciate any hint.

Regards,
Mike

Doug Schwarz

unread,
May 18, 2009, 9:20:26 PM5/18/09
to
In article <gut0nl$cl5$1...@fred.mathworks.com>,
"Mike Malkum" <e6c...@yahoo.com> wrote:

I hope you mean the additive inverse, -mod, or the multiplicative
inverse, 1./mod, because if you want to unmod something I'm afraid
you're out of luck.

Suppose you want to know if a number is even or odd,

B = mod(A,2);

Now B is either 0 or 1. Do you think there could be any way to get back
the original number, A, knowing only whether it is even or odd?

--
Doug Schwarz
dmschwarz&ieee,org
Make obvious changes to get real email address.

John D'Errico

unread,
May 18, 2009, 9:58:01 PM5/18/09
to
Doug Schwarz <s...@sig.for.address.edu> wrote in message <see-C77FF7.2...@news.frontiernet.net>...

> In article <gut0nl$cl5$1...@fred.mathworks.com>,
> "Mike Malkum" <e6c...@yahoo.com> wrote:
>
> > Hello everyone,
> > Is there any way to calculate the inverse of the mod operator in Matlab or
> > simulink?
> >
> > I appreciate any hint.
> >
> > Regards,
> > Mike
>
> I hope you mean the additive inverse, -mod, or the multiplicative
> inverse, 1./mod, because if you want to unmod something I'm afraid
> you're out of luck.
>
> Suppose you want to know if a number is even or odd,
>
> B = mod(A,2);
>
> Now B is either 0 or 1. Do you think there could be any way to get back
> the original number, A, knowing only whether it is even or odd?
>

Actually, there are some things one can do,
although the original question was not specific
enough to answer it.

For starters, is the OP asking for an additive
inverse or a multiplicative inverse? Both CAN be
done, within limits. An additive inverse always
exists in modular arithmetic. Thus 4 is the
additive inverse of 3, mod 7.

A multiplicative inverse is more difficult, since it
does not always exist. Here we are looking for
x such that mod(x*A,p) == 1. You can find a
tool for the modular (multiplicative) inverse in
my vpi toolbox, called minv.m. It uses the
extended Euclidean algorithm.

>> a = 35;
>> p = vpi(2^31 - 1);
>> ainv = minv(a,p)
ainv =
1656630242

>> mod(a*ainv,p)
ans =
1

HTH,
John

Mike Malkum

unread,
May 19, 2009, 12:17:02 AM5/19/09
to
"John D'Errico" <wood...@rochester.rr.com> wrote in message <gut3n9$a7u$1...@fred.mathworks.com>...

Thank you very much Guys, I really do appreciate your contributions.
My question came from a simulink block uses this equation:

wt = mod(A, 2*pi)

Now, if I know wt and pi, can I get the value of A?

John, if I use your vpi toolbox, can it calculate the value of A?

Many thanks

Doug Schwarz

unread,
May 19, 2009, 1:15:36 AM5/19/09
to
In article <gutbru$7ga$1...@fred.mathworks.com>,
"Mike Malkum" <e6c...@yahoo.com> wrote:


Not exactly, no. Think about it, suppose wt is 0.1. You can't know if
A is 2*pi + 0.1 or 4*pi + 0.1 or 6*pi + 0.1, etc.

However, if you're trying to unwrap phase and you have a vector of phase
values then take a look at the function unwrap.

Matt Fig

unread,
May 19, 2009, 2:12:02 AM5/19/09
to
"Mike Malkum" <e6c...@yahoo.com> wrote in message
>
>
> Thank you very much Guys, I really do appreciate your contributions.
> My question came from a simulink block uses this equation:
>
> wt = mod(A, 2*pi)
>
> Now, if I know wt and pi, can I get the value of A?
>
> John, if I use your vpi toolbox, can it calculate the value of A?
>
> Many thanks

I don't think you are THINKING about what the mod function does. Look closely at this example:

A = [1:20]*pi;
wt = mod(A, 2*pi)'

Study wt. Now suppose I randomly chose one element from A, and only showed you the corresponding element of wt. Could you tell me which element I chose from A with certainty?

Mike Malkum

unread,
May 19, 2009, 3:05:02 AM5/19/09
to
"Matt Fig" <spam...@yahoo.com> wrote in message <gutijh$90j$1...@fred.mathworks.com>...


Doug Matt, Thank you very much.

In fact, what I'm trying to find is the phase from the wt vector. (w=2*pi*f, and t is time). unfortunately when used d(unwrap (wt))/dt, I couldn't get the right phase of the signal. That is why I'm trying with the inverse of mod !

Matt, you're right, I didn't think much about the mod operator! with your example, it is now clear that impossible to give you the element from A you chose. But do you have any suggestions about the phase!

Once again, many thanks,
Mike

0 new messages