How to select specific points/intersections in a matlab plot?
Show older comments
I'm solving numerical analysis problems in which I need to find the the zeroes of certain equations with an error of less than 10^-2.
With the following code:
clc
format long
x = linspace(-1, 3, 1000);
y = ( abs( log(x + 1) ) -2 + x );
plot(x,y)
hold on
plot(x,0,'b')
I've managed to create two intersecting graphs as such:
What I want, though, is for Matlab to highlight the points where the y = 0 line intersects my original graph. That way I can know when to stop using the "successive bissections" method.
Answers (1)
madhan ravi
on 16 Mar 2019
idx=(abs(y)<1e-2);
% ^^^^----- tolerance (10^-2)
plot(x(idx),zeros(1,nnz(idx)),'sqb')

2 Comments
bobsoney bobsoney
on 16 Mar 2019
madhan ravi
on 16 Mar 2019
x0 = fsolve(@(xx) abs( log(xx + 1) ) -2 + xx ,[-.99,3]); % solve for x when y = 0
plot(x0,zeros(1,numel(x0)),'o','MarkerSize',10)
Categories
Find more on MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!