Borrar filtros
Borrar filtros

How to do symbolic mod operation

3 visualizaciones (últimos 30 días)
DmArcher
DmArcher el 24 de Abr. de 2017
Editada: DmArcher el 24 de Abr. de 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?

Respuesta aceptada

Steven Lord
Steven Lord el 24 de Abr. de 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 comentario
DmArcher
DmArcher el 24 de Abr. de 2017
Editada: DmArcher el 24 de Abr. de 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.

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by