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!