help using fzero to find the intersection

조회 수: 13 (최근 30일)
Ziad Badreldeen
Ziad Badreldeen 2020년 5월 29일
답변: Star Strider 2020년 5월 29일
i basically want to use fzero in order to find the coordinates of intersection between 2 graphs plotted together on the same figure can someone please explain how this is carried out

답변 (2개)

KSSV
KSSV 2020년 5월 29일
  댓글 수: 2
Ziad Badreldeen
Ziad Badreldeen 2020년 5월 29일
the question requires we use the fzero function for the problem
KSSV
KSSV 2020년 5월 29일
so attach your data..to find out whether fzero helps.

댓글을 달려면 로그인하십시오.


Star Strider
Star Strider 2020년 5월 29일
At the intersections, the difference between the functions is 0, and since fzero is a root-finding algorithm, choose and appropriate starting poiint and use it to find the intersections:
f = @(x) x.^2 - 2;
g = @(x) sin(2*pi*x/10);
for k = 1:2
xint(k) = fzero(@(x)f(x)-g(x), 5*(-1)^k); % Calculate ‘x’ At The Intersections
end
x = linspace(-2, 2);
figure
plot(x, f(x), x, g(x))
hold on
plot(xint, f(xint), 'gp') % Choose Either Function To Plot The Intersections
hold off
grid
Also, see the documentation on Anonymous Functions to understand how this code works.

카테고리

Help CenterFile Exchange에서 Optimization에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by