
How I can find co ordinates of intersection of two curves ?
10 ビュー (過去 30 日間)
古いコメントを表示
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);
0 件のコメント
回答 (3 件)
David Wilson
2019 年 7 月 28 日
編集済み: David Wilson
2019 年 7 月 28 日
Oh, looks like this is a common question: See (from 2016)https://au.mathworks.com/matlabcentral/answers/318475-how-to-find-the-intersection-of-two-curves?s_tid=answers_rc1-1_p1_MLT
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:

0 件のコメント
jahanzaib ahmad
2019 年 7 月 28 日
use polyxpoly function in mapping toolbox and get intersection points
0 件のコメント
参考
カテゴリ
Help Center および File 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!
