Effacer les filtres
Effacer les filtres

How to do symbolic mod operation

3 vues (au cours des 30 derniers jours)
DmArcher
DmArcher le 24 Avr 2017
Modifié(e) : DmArcher le 24 Avr 2017
I try to do mod function with symbolic variables. Is there a way to do something like mod(a+b,b)=a which means that the reminder of (a+b) divided by b is a. But MATLAB doesn't allow both the parameters of the mod function be symbolic. Could someone help me?

Réponse acceptée

Steven Lord
Steven Lord le 24 Avr 2017
When calling the mod function with symbolic inputs, the second input must be a matrix (which can be a vector or a scalar) of numbers or symbolic number.
"Divisor (denominator), specified as a number, symbolic number, or a vector or matrix of numbers or symbolic numbers."
The symbolic variable b isn't a number or symbolic number.
As for your statement that mod(a+b, b) is equal to a, that's not quite true.
a = 5;
b = 3;
equalsA = mod(a+b, b) == a % returns false
equivalentA = mod(a+b, b) == mod(a, b) % returns true
If you want to use symbolic numbers, you will need to wrap the commands that define equalsA and equivalentA in isAlways calls to convert them into true or false.
a = sym(5);
b = sym(3);
equalsA = isAlways(mod(a+b, b) == a) % returns false
equivalentA = isAlways(mod(a+b, b) == mod(a, b)) % returns true
  1 commentaire
DmArcher
DmArcher le 24 Avr 2017
Modifié(e) : DmArcher le 24 Avr 2017
Is there a way to compute in MATLAB about (2*a+b) to count that it contains two a and one b? So that I can use subtraction to get the reminder.

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by