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

1 visualizzazione (ultimi 30 giorni)
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 Commenti
Voss
Voss il 3 Mar 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 il 3 Mar 2023
Modificato: Mohammed AL Rashedi il 3 Mar 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,.....)

Accedi per commentare.

Risposta accettata

Voss
Voss il 3 Mar 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

Più risposte (0)

Categorie

Scopri di più su Risk Management Toolbox in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by