work with proportionality with vectors
4 ビュー (過去 30 日間)
古いコメントを表示
I have a vector
x=[1.05 2.023 3.1 4.014 12.112]
and another vector
y=[4.018 8.1 24.45]
how to detect that the values that follow the same proportionality with y are x(2) x(4) x(5) (proportionality with a tolerance)
I have been working in this for a long time and I do not get solution thanks
0 件のコメント
採用された回答
Walter Roberson
2017 年 3 月 4 日
If you want the tolerance to be absolute, then define
abs_tolerance = 0.1; %for example
matchfun = @(P) ismembertol(x.*P, y, 1, 'DataScale', abs_tolerance);
piff = @(P)-sum(matchfun(P));
If you want the tolerance to be relative, then define
rel_tolerance = 1e-2; %for example
matchfun = @(P) ismembertol(x.*P, y, rel_tolerance);
piff = @(P)-sum(matchfun(P));
Now you can minimize piff over a range of values to find the constant of proportionality that gives you the most matches to within the tolerance. How exactly you do that is left as an exercise to the reader ;-) But with that data, if you allow an absolute tolerance of 0.1, then the best match is P in the range [2.0115035592480548, 2.0267363824759945] which gives 3 matches.
With the optimal P in hand,
selected_x = x(matchfun(P));
As for how to minimize: I suggest
P_range = linspace(LowerBound, UpperBound,5000);
results = arrayfun(piff, P_range);
acceptable_P = P_range(results == min(results));
and now select one of the acceptable_P as your representative P
2 件のコメント
Walter Roberson
2017 年 3 月 4 日
fminsearch has to be provided with a single guess per variable, not a range. If the range is 0 to 4 use those as the lower and upper bound with the linspace and arrayfun I show.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!