work with proportionality with vectors
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Luca cadalo
el 3 de Mzo. de 2017
Comentada: Walter Roberson
el 4 de Mzo. de 2017
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 comentarios
Respuesta aceptada
Walter Roberson
el 4 de Mzo. de 2017
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 comentarios
Walter Roberson
el 4 de Mzo. de 2017
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.
Más respuestas (0)
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!