åªæ¯è¦ç»æçè¯ï¼æ²¡å¿ è¦ç»åï¼åªè¦æ±åºRä¸Aï¼Bä¹é´å¯¹åºå ³ç³»å³å¯ãå¯ä»¥ç¨è¿ä»£æ³æè 代æ°æ³æ±è§£ãè¿ä»£æ³å°±æ¯ä»åå§åå¾å¼å§ï¼ä¸æç´¯å 0.5å»å°è¯ï¼å¹¶ä¸ä¸æ交æ¿åæ¢Aï¼Bå¼ï¼ç´å°å°è¾¾ç®æ åå¾ã代æ°æ³å°±æ¯ç®åºåå¾ä¸è¾åºä¹é´çå ¬å¼å ³ç³»ï¼ç¶åå°è¦æ±çRç´æ¥å¸¦å ¥æ±è§£ã(å¦æä½ éè¦ç»åï¼é£ä¹åªæ¯ç»å¾æå·§ä¸çé®é¢ï¼åç®æ³æ²¡å ³ç³»)
代ç åææå¾å¦ä¸ï¼
clc
clear all
close all
%== åå§å¼ ==%
r0 = 1; % æéé¢é£ä¸ªåçåå¾
d = 0.5; % åå¾å¢é
%===========%
R = 4; % è¦æ±è§£çåå¾
%== è¿ä»£æ³ ==%
K = 1; % æ å¿ä½ï¼1-è¾åºA=2ï¼B=1ï¼0-è¾åºA=1ï¼B=2
N = 1; % ä»éå¾å¤æ°ç¬¬N个å
r = r0;
while(r<R)
N = N + 1;
K = ~K;
r = r0+(N-1)*d;
end
if(K==1)
A = 2;
B = 1;
else
A = 1;
B = 2;
end
fprintf('R=%f, A=%d, B=%d\n', R, A, B);
%===========%
%== 代æ°æ³ ==%
% å¯ä»¥çåºï¼ç¬¬å¥æ°ä¸ªåè¾åºé½ä¸ºA=2,B=1ï¼ç¬¬å¶æ°ä¸ªåè¾åºé½ä¸ºA=1,B=2
N_cal = (R-r0)/d+1; % æ±åºæ¯ç¬¬å 个å
if(mod(N_cal,2)==0)
A_o = 1; B_o = 2;
else
A_o = 2; B_o = 1;
end
fprintf('R=%f, A_o=%d, B_o=%d\n', R, A_o, B_o);
%============%
%== å¦æä½ æ³çä¸åRä¸è¾åºåå ==%
R = 1:0.5:5; % æ¥çRä»1~20ååæ¶è¾åº
A_o_m = zeros(1, length(R));
B_o_m = zeros(1, length(R));
N_cal_m = (R-r0)./d+1; % æ±åºæ¯ä¸ªRåå«å¯¹åºç¬¬å 个å
for i=1:length(R)
if(mod(N_cal_m(i),2)==0)
A_o_m(i) = 1; B_o_m(i) = 2;
else
A_o_m(i) = 2; B_o_m(i) = 1;
end
end
figure
A_B = [A_o_m; B_o_m]';
h = stem(R,A_B);
set(h(1),'MarkerFaceColor','blue') % èè²-A
set(h(2),'MarkerFaceColor','red','Marker','square') % 红è²-B
追é®å¦æåæ ·ç模åï¼è½¬æ¢æç´è§åæ å¢ï¼
追çåä»ä¹åæ ç³»æ²¡å ³ç³»ï¼å ³é®æ¯Rä¸A,Bä¹é´çå ³ç³»ï¼è¿ä¸ªå ³ç³»ä¸åç»æé½ä¸æ ·
追é®ä¸åï¼æ¨¡åæ¯å¨æåç¯ï¼ä½æ¯å¸¦å ¥è®¡ç®æè¦ç¨ç´è§åæ
ï¼
å¨ï¼
å¦æmodåä¸æ¯æ´æ°æä¹å¤ç
追ç1ãæè°çåç¯åªæ¯é¢ç®è®¾å®èå·²ï¼çæ£æç¨çåªæ¯åå¾R
2ãæè°æåæ ãç´è§åæ ç³»é½åªæ¯ä»ä¸åçæè¿°è§åº¦æè¿°åä¸ä¸ªäºç©ï¼å¯ä»¥ç¸äºè½¬æ¢çï¼æ以没ææ¬è´¨å·®å¼
3ã对äºmodåä¸æ¯æ´æ°çé®é¢ï¼è¯´æææ±çåå¾æ¯å¤äºåç¯å
é¨ãè¿æ¶åå°±çé¢è®¾çè¦æ± ï¼å¦æ没æç¹å«è®¾å®çè¯ï¼é£æ´ä¸ªåç¯éä»»ä½ä¸ä¸ªåå¾çå对åºçAï¼Bé½ç¸åãé£ä¹åªè¦å¤å®æ¯å¨åªä¸ªåç¯å³å¯ï¼å æ¤å
è¦å¯¹N_cal è¿è¡åæ´å¤çï¼åä¸åæ´æè
åä¸åæ´é½å¯ä»¥ï¼åç»å¤æè¯å¥åç¸åºå¾®è°å³å¯