Finding multiple x values in plot for given y
14 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Geroge Papas
el 17 de Dic. de 2020
Respondida: Geroge Papas
el 17 de Dic. de 2020
I have to find the values for x when y=0 but i cant seem to make it work. I have tried with interp1 but it seems that it gives me an answer of x=2.3490 which is clearly wrong,since there are 2 points in the plot where y=0. Here's the code:
x = [0:0.001:pi]
f = exp(x/4).*sin(x)-1;
plot(x,f)
xlabel('Axis x');
ylabel('Axis y');
newLim = get(gca,'XLim');
newx = linspace(newLim(1), newLim(2), 30);
set(gca,'XTick', newx);
% what I tried:
yi = 0 ;
xi = interp1(f,x,yi) ;
hold on
semilogy(xi,yi,'*r')
Respuesta aceptada
Más respuestas (1)
Daniel Pollard
el 17 de Dic. de 2020
I think you want fsolve. Give it a function handle and an initial starting point, and it'll tell you (approximately) what x gives f(x)=0.
0 comentarios
Ver también
Categorías
Más información sobre Graphics Object Programming 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!