How to assign values to variables in sym function in matlab while finding out modulus?

StackOverflow https://stackoverflow.com/questions/22486839

  •  16-06-2023
  •  | 
  •  

Pergunta

While finding out modulus while dealing with very large numbers, i used the sym tool.

Usage of sym tool E.g:

a=5; b=2; 

c=sym('a^b');

mod(c,10)

ans= a^b mod 10

The answer should be clearly 5,but it does not pass values to the variables.

The sym tool is very necessary when the inputs are very high i.e a,b,c > 500.

Foi útil?

Solução

Solution using symbolic toolbox:

a=sym(5)
b=sym(2)
c=sym(10)
mod(a^b,c)

Another possibility that might help you with big numbers:

a=5
b=2
c=10
ar=mod(a,c)
mod(ar^b,c)

This gives the same result, but might reduce the required range drastically.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top