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

조회 수: 1 (최근 30일)
Mohammed AL Rashedi
Mohammed AL Rashedi 2023년 3월 3일
댓글: Mohammed AL Rashedi 2023년 3월 3일
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일
편집: 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