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

조회 수: 18 (최근 30일)
Gyan Swarup Nag
Gyan Swarup Nag 2021년 3월 1일
답변: darova 2021년 3월 2일
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에서 Surface and Mesh Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by