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
Matt J
2017년 11월 9일
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?

답변 (1개)
John D'Errico
2017년 11월 9일
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?
카테고리
도움말 센터 및 File Exchange에서 Direct Search에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!