How to do symbolic mod operation

3 次查看(过去 30 天)
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?

采纳的回答

Steven Lord
Steven Lord 2017-4-24
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 个评论
DmArcher
DmArcher 2017-4-24
编辑:DmArcher 2017-4-24
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Number Theory 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by