필터 지우기
필터 지우기

How to do symbolic mod operation

조회 수: 3 (최근 30일)
DmArcher
DmArcher 2017년 4월 24일
편집: DmArcher 2017년 4월 24일
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