How I can find co ordinates of intersection of two curves ?

조회 수: 9 (최근 30일)
Manoj Balaji Mungde
Manoj Balaji Mungde 2019년 7월 28일
댓글: jahanzaib ahmad 2019년 7월 28일
theta=0:pi/400:2*pi; x=sin(pi*theta)+cos(pi*theta); y=cos(pi*theta)-2*sin(pi*theta); x1=sin(pi*theta)+cos(pi*theta)+2; plot(y,x,y,x1);

답변 (3개)

David Wilson
David Wilson 2019년 7월 28일
편집: David Wilson 2019년 7월 28일
In any case ...
One (lazy) way is to numerically solve for the multiple roots using fsolve from the optimisation toolbox. You have two roots, so you need to do this twice.
theta=0:pi/400:2*pi;
x=sin(pi*theta)+cos(pi*theta);
y=cos(pi*theta)-2*sin(pi*theta);
x1=sin(pi*theta)+cos(pi*theta)+2;
plot(y,x,y,x1);
grid on
xlabel('y'); ylabel('x');
For some strange reason you have swapped the x & y axes, which is confusing, but not necessarily wrong. In any case, we can see that tentative approx solutions are (x=1.6, y=-1.6) and (x=0.7, y=1.5). This we can refine with fsolve. Note that I also use fsolve to get decent starting guesses for theta (ie. t) given that I only really have a decent idea for x(t), y(t). This is probably unnecessary, but will help if, and when, you decide to try something more challenging.
f1 = @(t) sin(pi*t)+cos(pi*t)
f2 = @(t) cos(pi*t)-2*sin(pi*t)
f3 = @(t) sin(pi*t)+cos(pi*t)+2;
% Need to solve this ...
fun = @(t) [f1(t(1)) - f3(t(2)); ...
f2(t(1)) - f2(t(2))];
% Find t near start points
t0 = fsolve(@(t) [f1(t)-1.6; f2(t)+1.5], [1;1]);
t = fsolve(fun,t0); % Now solve for real
x = f1(t(1)); y = f2(t(1));
hold on
plot(y,x,'rs');
% do again for the other intersection
t0 = fsolve(@(t) [f1(t)-0.7; f2(t)-1.5], [1;1]);
t = fsolve(fun,t0);
x = f1(t(1)); y = f2(t(1));
plot(y,x,'rs');
hold off
Checking the intersections gives:

jahanzaib ahmad
jahanzaib ahmad 2019년 7월 28일
use polyxpoly function in mapping toolbox and get intersection points

jahanzaib ahmad
jahanzaib ahmad 2019년 7월 28일

카테고리

Help CenterFile Exchange에서 Genomics and Next Generation Sequencing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by