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

4 visualizzazioni (ultimi 30 giorni)
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*');
  2 Commenti
Gyan Swarup Nag
Gyan Swarup Nag il 1 Mar 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
Agniva Sengupta
Agniva Sengupta il 13 Feb 2025 alle 19:16
getContourLineCoordinates and intersections need to be downloaded from file exchange for the snippet above to work.

Accedi per commentare.

Risposta accettata

darova
darova il 2 Mar 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

Più risposte (1)

KSSV
KSSV il 1 Mar 2021
  1 Commento
Gyan Swarup Nag
Gyan Swarup Nag il 1 Mar 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.

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by