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 日
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 Center および File ExchangeRisk Management Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by