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

5 次查看(过去 30 天)
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 个评论
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

请先登录,再进行评论。

采纳的回答

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 CenterFile Exchange 中查找有关 Fit Postprocessing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by