Listing possible combinations of integers, given constraints (Gear Ratio Related)

5 ビュー (過去 30 日間)
Terence Ng
Terence Ng 2018 年 9 月 13 日
コメント済み: Terence Ng 2018 年 9 月 13 日
The problem:
Let Gear Ratio = ( 1 + N3/N1 )/( 1 - ( ( N3*N4 )/( N5*N2) ) ), where N1, N2, ..., N5 must be integers. I'm looking to list combinations of N1, N2, ..., N5 that make the gear ratio fall within a specified range (i.e. 50 - 60), with upper limits to what the values of N1, N2, ..., N5 can be (i.e. 150).
I've done it using a for loop then and listing / filtering values that are within the given constraints, but am looking for a more efficient solution given that the for loop takes forever to finish.
I looked into using ndgrid from the following example:
But the arrays created would be much too large.
Any ideas / hints would be appreciated!
  2 件のコメント
Terence Ng
Terence Ng 2018 年 9 月 13 日
Based on the equation, you're correct that N2 and N5 can be combined and substituted afterwards.
As Aquatris mentioned below, assuming I went with a "brute force" method I'd still be 4 for loops deep.
More than likely I'll revisit the problem and apply more constraints to reduce the number of solution sets.


回答 (1 件)

Aquatris 2018 年 9 月 13 日
編集済み: Aquatris 2018 年 9 月 13 日
One possibility is using an optimization. Here is a simple code for it using OPTI toolbox;
clear all,clc
% round() is used to enforce integer value
gr = @(N) (1+round(N(3))/round(N(1)))/(1- round(N(3))*round(N(4))/round(N(5))/round(N(2))));
% initial guess
x0 = [1 2 3 7 11]';
% lower and upper bounds for N = [N1 N2 N3 N4 N5]'
lb = zeros(5,1);
ub = ones(5,1)*150;
% Nonlinear Constraints for desired gear ratio range(cl <= nlcon(x) <= cu)
nlcon = @(x) gr(x);
cl = [50];
cu = [90]; % upper is chosen 90 cause initial guess give 88
% formulate the problem in OPTI toolbox
Opt = opti('fun',gr,'bounds',lb,ub,'x0',x0,'nl',nlcon,cl,cu)
[x,fval,exitflag,info] = solve(Opt); % this will try to minimize the
% gr function and since the lower
% limit is defined as 50, it will
% give a gear ratio close to 50
% if optimization is succesful
N_solution = round(x) % the necessary [N1 N2 N3 N4 N5]' = [2 2 3 7 11]'
gear_ratio = gr(N_solution) % achieved gear ratio = 55
The problem can be formulated in a similar manner for built-in Matlab function as well.
  3 件のコメント
Terence Ng
Terence Ng 2018 年 9 月 13 日
This is currently the method I have. (I also gave up way before n1 was able to iterate once)
I agree with your statement that it doesn't seem feasible to find all the combinations, likely I'll have to apply more constraints to reduce the number of possible solutions.





Community Treasure Hunt

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

Start Hunting!

Translated by