Count the number of intersections between any two curves

15 ビュー (過去 30 日間)
SATHYA PRIYA SUGUMAR
SATHYA PRIYA SUGUMAR 2019 年 11 月 11 日
編集済み: Matt J 2019 年 11 月 11 日
Hi all,
I have two curves and I need to find and count the number of times they intersect. Is there any matlab function to do so?
  2 件のコメント
Dimitris Kalogiros
Dimitris Kalogiros 2019 年 11 月 11 日
Do you have an analytical function for each of these curves or you have just two arrays containing samples of these curves at some time instances ?
SATHYA PRIYA SUGUMAR
SATHYA PRIYA SUGUMAR 2019 年 11 月 11 日
I have two analytical functions.

サインインしてコメントする。

回答 (2 件)

Matt J
Matt J 2019 年 11 月 11 日
編集済み: Matt J 2019 年 11 月 11 日
The only general way (i.e., for arbitrary curves) is using the Symbolic Math Toolbox,
solve(curve1==curve2)

Dimitris Kalogiros
Dimitris Kalogiros 2019 年 11 月 11 日
編集済み: Dimitris Kalogiros 2019 年 11 月 11 日
If you have two functions y=f(t) and y=g(t) you can find their intersections by solving the equation f(t)=g(t). But such a thing (maybe) should be an impossible task.
So, here you are a more general approach
clearvars;
clc;
syms t f(t) g(t)
%define functions
f(t)=(t^2)+3*sin(2*pi*t)-2
g(t)=exp((1/2)*t)
%plot the functions
fplot(f(t)); hold on;
fplot(g(t));
%refine plot
grid on;
legend('f', 'g');
ax = gca;
ax.YAxisLocation='origin';
ax.XAxisLocation='origin';
%determine intersections
downLimit=-5; upperLimit=5; %area of searching
dt=0.1; % accuracy step (it should be small enough)
rootCounter=0;
h(t)=f(t)-g(t);
for t=downLimit:dt:upperLimit
if h(t)==0 %f(t)=g(t)
rootCounter=rootCounter+1;
elseif h(t)*h(t+dt)<0 % f(to)=g(to), t<to<t+dt
rootCounter=rootCounter+1;
end
end
fprintf('found %d roots', rootCounter);
  1 件のコメント
Dimitris Kalogiros
Dimitris Kalogiros 2019 年 11 月 11 日
.... and here you are what you get, when you run this code
demo.jpg

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeInterpolation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by