my error when i wrote that x*x or x^2 is not working

1 visualización (últimos 30 días)
n=1:100;
x=0:1;
for i=1:length(n)
x^2 = mod(x,n(i));
Incorrect use of '=' operator. Assign a value to a variable using '=' and compare values for equality using '=='.
end
i want to get all value of n where x=0 And x = 1 onnnllly
  4 comentarios
Voss
Voss el 3 de Mzo. de 2023
"is true whene n = 7,25,13,...."
What's true when n = 7, 25, 13, ...?
What are you actually trying to do?
Mohammed AL Rashedi
Mohammed AL Rashedi el 3 de Mzo. de 2023
Editada: Mohammed AL Rashedi el 3 de Mzo. de 2023
Now , let x^2 = x mod 7 then we have only two solution x=0 and x=1.
Simillary ,
let x^2 = x mod 25 then we have only two solution x=0 and x=1.
so now i want to conversely.
let there are two solutions x=0 and x=1 (only) i want to get n (n=7 ,n=25,.....)

Iniciar sesión para comentar.

Respuesta aceptada

Voss
Voss el 3 de Mzo. de 2023
Maybe this:
n=1:100;
n_true = [];
for i=1:length(n)
x = 2:n(i)-1;
x2 = mod(x.^2,n(i));
if ~any(x2 == x)
n_true(end+1) = n(i);
end
end
disp(n_true);
Columns 1 through 33 1 2 3 4 5 7 8 9 11 13 16 17 19 23 25 27 29 31 32 37 41 43 47 49 53 59 61 64 67 71 73 79 81 Columns 34 through 36 83 89 97

Más respuestas (0)

Categorías

Más información sobre Risk Management Toolbox en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by