Solving systems of linear congruences in MATLAB

6 visualizzazioni (ultimi 30 giorni)
I've noticed many questions over the years where someone would like to find all integer solutions to a problem. And often it is the case the problem posed it not as easy as the ones I'll offer here. But I was hoping I might see how others on Answers would attack such a problem. (Yes, I can answer this question myself, and I will probably offer an answer at some point, but I'd love to learn from others, as I am sure you can offer some sage advice, on what I think are interesting problems.)
So what am I asking? Here are several variations of linear congruential systems of equations. The simplest is something the Chinese Remainder Theorem should handle. I'll write using the symbolic TB, but there should be no need to use it for the solution. So, solve for x, such that
syms x
M = [11;15;7];
b = [5;7;4];
mod(x,M) == b
ans = 
And my question here, is to solve for the general set of all integers, such that that relation holds true. Again, a basic application of the Chinese remainder theorem should suffice there.
But now, what if the problem is made slightly more interesting? So perhaps a linear system of two linear congruences.
syms x y
A = [1 -1;2 3];
M = 7;
b = [3;5];
mod(A*[x;y],M) == b
ans = 
But now, suppose we again change the problem to be a little more difficult, with different moduli?
How would you solve this problem?
M = [10;11];
mod(A*[x;y],[10;11]) == b
ans = 
(Hey, it could have been worse. I could be asking for solutions to higher order variations of Pell equations, or something of the sort.)
Again, the target in all of these is to characterize the set of all solutions to such a problem. And while I could post immediate solutions, I don't want to stifle others from suggesting methods that might be better than what I chose. My goal in all of this is to learn better methods, and I may not find that if I tell you how I would solve the problem.
I've attached three helper functions I've written, rrefgf, powerMod, and modInv. modInv is a nice little tool. I'll be posting them in a small toolbox on the file exchange.

Risposte (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by