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.

Réponses (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 commentaires

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)

Connectez-vous pour commenter.

Catégories

En savoir plus sur MATLAB dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by