How to find the point of intersection of two level curves?

18 visualizaciones (últimos 30 días)
Gyan Swarup Nag
Gyan Swarup Nag el 1 de Mzo. de 2021
Respondida: darova el 2 de Mzo. de 2021
I have two functions $z1 = (1-2.2*x-0.1*y).*(2-2.3*x-0.1*y)-(1-x+y).*(1-x+y);
z2 = (2-x-2*y).*(-1+.1*x-4*y)-(1+.2*x+.1*y).*(1+.2*x+.1*y)$
I want to find the point of intersection of the level curves of the two functions. Can anyone help in this regard?
I have implimented a code which I am attaching below but in that code I could not get all the points
clc; clear all
[x,y] = meshgrid(-3:0.01:3,-3:0.01:3);
z1 = (1-2.2*x-0.1*y).*(2-2.3*x-0.1*y)-(1-x+y).*(1-x+y);
z2 = (2-x-2*y).*(-1+.1*x-4*y)-(1+.2*x+.1*y).*(1+.2*x+.1*y);
% Calculate the coordinates of the contour lines
% (here, just the contour line at z = 0)
C1 = contourcs(x(1,:),y(:,1),z1,[0 0]);
C2 = contourcs(x(1,:),y(:,1),z2,[0 0]);
% Use polyxpoly to find intersections
for ic = 1:length(C1)
[xint1{ic}, yint1{ic}] = polyxpoly(C1(ic).X, C1(ic).Y, C2(ic).X, C2(ic).Y);
end
xint1 = cat(1, xint1{:});
yint1 = cat(1, yint1{:});
% Plot the results
figure;
contour(x,y,z1,[0 0]);
hold on;
contour(x,y,z2,[0 0]);
plot(xint1, yint1, 'r*');
  1 comentario
Gyan Swarup Nag
Gyan Swarup Nag el 1 de Mzo. de 2021
[x,y] = meshgrid(-3:0.01:3,-3:0.01:3);
z1 = (1-2.2*x-0.1*y).*(2-2.3*x-0.1*y)-(1-x+y).*(1-x+y);
z2 = (2-x-2*y).*(-1+.1*x-4*y)-(1+.2*x+.1*y).*(1+.2*x+.1*y);
[C1,h] = contour(x,y,z1,[0 0],'*k')
hold on
[C2,h]= contour(x,y,z2,[0,0]);
contourTable1 = getContourLineCoordinates(C1)
contourTable2 = getContourLineCoordinates(C2)
[xi,yi] = intersections(contourTable1.X,contourTable1.Y,contourTable2.X,contourTable2.Y)
plot(xi, yi, 'ko')
This code is working

Iniciar sesión para comentar.

Respuesta aceptada

darova
darova el 2 de Mzo. de 2021
You need double for loop
k = 0;
for ic = 1:length(C1)
for jc = 1:length(C2)
k = k + 1;
[xint1{k}, yint1{k}] = polyxpoly(C1(ic).X, C1(ic).Y, C2(jc).X, C2(jc).Y);
end
end

Más respuestas (1)

KSSV
KSSV el 1 de Mzo. de 2021
  1 comentario
Gyan Swarup Nag
Gyan Swarup Nag el 1 de Mzo. de 2021
The link you provides discuss about a function which is dependint on one variable but in my case the functions are depending on two variables. I could not understand how to use this function.

Iniciar sesión para comentar.

Categorías

Más información sobre Surface and Mesh Plots en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by