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

1 次查看(过去 30 天)
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 个评论
Voss
Voss 2023-3-3
"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 2023-3-3
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,.....)

请先登录,再进行评论。

采纳的回答

Voss
Voss 2023-3-3
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Risk Management Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by