How to find x-values when y-function equals a set value?
110 次查看(过去 30 天)
显示 更早的评论
Hi, there!
New to matlab.. I have a dilema trying to find the x-values for a function =0.7(see figure). And I should be able to find both values of x when the bell-curve changes.
Big help, please! I've tried fzero, and other functions and mostly does't work or it will just give me one single value of x. there should always be 2.
Thank you in advance!
x=[0.46 0.7]
f=(a1*exp(-((x-b1)/c1).^2))=0.7
The a1, b1 and c1 values are known.
0 个评论
采纳的回答
Star Strider
2020-10-16
编辑:Star Strider
2020-10-18
Try this:
x = linspace(0.54, 0.61); % Create Data
y = exp(-(x-0.58).^2*1E+4); % Create Data
idx = find(diff(sign(y-0.7)));
for k = 1:numel(idx)
idxrng = [-1 1]+idx(k);
x7(k) = interp1(y(idxrng), x(idxrng), 0.7); % Interpolate To Find Intersection ‘x’-Value
end
figure
plot(x, y)
hold on
plot(xlim, [1 1]*0.7, ':k', 'LineWidth',1) % Reference Line
plot(x7, [1 1]*0.7, 'pg','MarkerFaceColor','g','MarkerSize',10) % Intersections
plot([1 1]*x7(1), [min(ylim) 0.7], ':k')
plot([1 1]*x7(2), [min(ylim) 0.7], ':k')
hold off
legend('Data','Reference','Intersections', 'Location','NW')
Use your own function for ‘y’. I would have used it, however the parameters are nowhere to be found.
EDIT — (18 Oct 2020 at 19:37)
Added plot image —
.
7 个评论
Star Strider
2020-10-20
As always, my pleasure!
After about a half hour of experimentation with the fitting (all unsuccessful), I simply used the raw data, and use the if block to trap segments that either did not reach the 0.7 level or that did not have 2 intercepts with it.. The fitting is likely not necessary (or at least a different model would be necessary, since the Gaussian gives a very poor approximation). I do not know what your data are, however if you want to fit them (although I do not recommend that), a sinc function of some sort (with more parameters, for example amplitude, position, and width) could be more appropriate than the Gaussian.
(For the record, I am male.)
更多回答(2 个)
KSSV
2020-10-16
You can take your curve as L1 and define your straight line at y = 0.7 as curve L1 and use InterX. Get the function InterX from:
Alan Stevens
2020-10-16
With your particular function you can get both values of x immediately from
x = b1 + c1*sqrt(log(a1/0.7))*[1, -1];
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Interpolation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!