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 Center および File ExchangeStatistics and Machine Learning Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by