
How to find x-values when y-function equals a set value?
    49 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    Coryn Melissa LLamoza Carabali
 el 16 de Oct. de 2020
  
    
    
    
    
    Comentada: Star Strider
      
      
 el 20 de Oct. de 2020
            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 comentarios
Respuesta aceptada
  Star Strider
      
      
 el 16 de Oct. de 2020
        
      Editada: Star Strider
      
      
 el 18 de Oct. de 2020
  
      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 comentarios
  Star Strider
      
      
 el 20 de Oct. de 2020
				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.)  
Más respuestas (2)
  KSSV
      
      
 el 16 de Oct. de 2020
        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
      
      
 el 16 de Oct. de 2020
        With your particular function you can get both values of x immediately from
x = b1 + c1*sqrt(log(a1/0.7))*[1, -1];
Ver también
Categorías
				Más información sobre Descriptive Statistics 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!



