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

4 ビュー (過去 30 日間)
Gyan Swarup Nag
Gyan Swarup Nag 2021 年 3 月 1 日
コメント済み: Agniva Sengupta 2025 年 2 月 13 日 19:16
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 件のコメント
Gyan Swarup Nag
Gyan Swarup Nag 2021 年 3 月 1 日
[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 2025 年 2 月 13 日 19:16
getContourLineCoordinates and intersections need to be downloaded from file exchange for the snippet above to work.

サインインしてコメントする。

採用された回答

darova
darova 2021 年 3 月 2 日
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

その他の回答 (1 件)

KSSV
KSSV 2021 年 3 月 1 日
  1 件のコメント
Gyan Swarup Nag
Gyan Swarup Nag 2021 年 3 月 1 日
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.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSurface and Mesh Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by