Intersection between the two curves

2 次查看(过去 30 天)
guru k
guru k 2019-8-29
How to get the intersection between the two curves (Red Color & Blue Color) shown in figure above?
Any coding to get the point of intersection?
  3 个评论
Star Strider
Star Strider 2019-8-29
guru k’s Answer moved here —
I have to find out the intersection between the two curve equations plotted above? I have given the plots.

请先登录,再进行评论。

回答(1 个)

Star Strider
Star Strider 2019-8-29
This approximates your data and calculates and plots the intersections:
t = linspace(0, 1500, 250); % Independent Variable
f1 = 100*sin(2*pi*t/100); % First Curve
f2 = 10*sin(2*pi*t/100) - t*0.2; % Second Curve
zci = @(v) find(v(:).*circshift(v(:), [-1 0]) <= 0); % Returns Approximate Zero-Crossing Indices Of Argument Vector
df = f1 - f2;
fzx = zci(df);
for k = 2:numel(fzx)-1 % Interpolation Loop (Do Not Include First Or Last Values)
ixr = [fzx(k)-1 fzx(k)+1]; % Interpolation Index Range
tv = t(ixr);
dv = df(ixr);
B = [tv(:) [1; 1]] \ dv(:); % Estimate Parameters
ti(k) = -B(2) / B(1); % ‘t’ At Zero-Crossing
f1v(k) = interp1(tv, f1(ixr), ti(k)); % ‘f1’ At Intersection
f2v(k) = interp1(tv, f2(ixr), ti(k)); % ‘f2’ At Intersection
end
figure
plot(t, f1, t, f2) % Plot Curves
hold on
plot(ti, f1v, 'x', ti, f2v, '+') % Plot Intersections
hold off
grid

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by