If文、for文を回し、パラスタを実行したが、出てこない答えがある。
Show older comments
条件を満たすような5つの変数のパターンの組み合わせを全て出したいです。(パラスタを行いたい)
for文、if文を使用し、条件を満たさなければ、直ちに次のパラスタを実行するようなものが理想です。
自分で一回コードを組みましたが、(Za、Zb、Zc、Zd、Ze)=(11、11、34、12、38)も答えになるはずなのに、解析結果に出てきません。何がいけないのでしょうか…
▼やりたいこと
任意の値:P=5
変数:Za、Zb、Zc、Zd、Ze (全て整数で、値は5~100の範囲)
条件:U=Zc/Za>1
V=(Zb・Ze)/(Zc・Zd)>1
W=(Zb・Ze)/(Za・Zd)>1
X=(Za+Zc)/N (整数)
Y=(Za・Zd+Zb・Ze)/(P・(ZbとZdの最大公約数)) (整数)
Z=(Zc・ZdーZb・Ze)/(P・(ZbとZdの最大公約数)) (整数)
R=(Za+Zc)/P (整数)
I=(V+W)/(V-1)=171
出力イメージとしては、
(Za、Zb、Zc、Zd、Ze)=(11、11、34、12、38)
・
・
・
clear
N=100;%%歯数範囲指定
P=5; %%ピニオンの数
K=1;
for Za=5:N %探索歯数範囲
for Zb=5:N %探索歯数範囲
for Zc=5:N %探索歯数範囲
for Zd=5:N %探索範囲
for Ze=5:N %探索範囲
U=Zc/Za; %i0
V=(Zb*Ze)/(Zc*Zd); %i0'
W=(Zb*Ze)/(Za*Zd); %i0"
if U<=1
continue
end
if V<=1
continue
end
if W<=1
continue
end
if W<=U
continue
end
if W<=V
continue
end
I=(V+W)/(V-1); %減速比計算
if I~=171 %希望の減速比を入れてね…!!
continue
end
Q=gcd(Zb,Zd); %ZbとZdの最大公約数
X=(Za+Zc)/P;
Y=(Za*Zd+Zb*Ze)/(P*Q);
Z=(Zc*Zd-Zb*Ze)/(P*Q);
R=(Za+Zc)/P;
if X~=floor(X)
continue
end
if Y~=floor(Y)
continue
end
if Z~=floor(Z)
continue
end
if R~=floor(R)
continue
end
A(K,:)=[Za Zb Zc Zd Ze];
K=K+1;
end
end
end
end
end
Accepted Answer
More Answers (0)
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!