Find intersections by using fzero
Show older comments
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 Comment
Matt J
on 9 Nov 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?

Answers (1)
John D'Errico
on 9 Nov 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?
Categories
Find more on Direct Search 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!