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

1 view (last 30 days)

Show older comments

##### 0 Comments

### Answers (3)

David Wilson
on 28 Jul 2019

Edited: David Wilson
on 28 Jul 2019

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 Comments

jahanzaib ahmad
on 28 Jul 2019

use polyxpoly function in mapping toolbox and get intersection points

##### 0 Comments

### See Also

### Categories

### Community Treasure Hunt

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

Start Hunting!