MATLAB Answers

0

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

Asked by Manoj Balaji Mungde on 28 Jul 2019
Latest activity Commented on by jahanzaib ahmad on 28 Jul 2019
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 Comments

Sign in to comment.

Tags

3 Answers

Answer by David Wilson on 28 Jul 2019
Edited by David Wilson on 28 Jul 2019

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

Sign in to comment.


Answer by jahanzaib ahmad on 28 Jul 2019

use polyxpoly function in mapping toolbox and get intersection points

  0 Comments

Sign in to comment.