Intersection between the two curves
2 views (last 30 days)
Show older comments
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 Comments
Adam Danz
on 29 Aug 2019
This FEX function would work well with that problem.
Star Strider
on 29 Aug 2019
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.
Answers (1)
Star Strider
on 29 Aug 2019
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
0 Comments
See Also
Categories
Find more on Annotations 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!