How to select specific points/intersections in a matlab plot?

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)

idx=(abs(y)<1e-2);
% ^^^^----- tolerance (10^-2)
plot(x(idx),zeros(1,nnz(idx)),'sqb')
Screen Shot 2019-03-16 at 8.04.51 PM.png

2 Comments

I'm not allowed to use advanced commands I haven't been taught in class yet.
Thanks for the answer, but I'd like to know strictly how to intersect and hightlight the intersections of those graphs.
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)

Sign in to comment.

Categories

Find more on MATLAB in Help Center and File Exchange

Asked:

on 16 Mar 2019

Commented:

on 16 Mar 2019

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!