Find intersections by using fzero

How to find the intersections between two functions by using "fzero"? Take for example these two functions: f(x) = exp(-x^2 / 2) and g(x) = x^2 -3x + 2. How to find the intersections between them by using fzero?
Thanks so much!

1 comentario

Matt J
Matt J el 9 de Nov. de 2017
It's a horrible homework question. To find all of the intersections, you must know how many to search for and where. It is easy to show that,
g(x)<=1<f(x)
outside the interval [0.3,2.7] and therefore any intersections have to happen in this interval. It is also clear from the plot below that f(x)-g(x)=0 has at least two roots in this interval. However, how do you know that there aren't more, lurking unsampled between the points shown in the plot?

Iniciar sesión para comentar.

Respuestas (1)

John D'Errico
John D'Errico el 9 de Nov. de 2017
1. Create a new function that is the difference of them. I'll give you this one, because many people misunderstand how to use function handles.
f = @(x) exp(-x.^2/2);
g = @(x) x.^2 - 3*x +2;
h = @(x) g(x) - f(x);
2. Use fzero. You need to expend some thought here. Read the help for fzero.
WTP?

Etiquetas

Preguntada:

el 9 de Nov. de 2017

Comentada:

el 9 de Nov. de 2017

Community Treasure Hunt

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

Start Hunting!

Translated by