How can I find intersection points without mouse?

Hi,
I hope you are keeping safe.
Couls you please help me regarding my matlab code, It is urgent and I would appreciate if you help me. I want to find intersections in this plot without mouse(Using code).
%% Input Parameters
clear all
clc
alpha1=input('Enter positive "alpha1"?');
alpha2=input('Enter positive "alpha2"?');
beta1=input('Enter positive "beta1"?');
beta2=input('Enter positive "beta2"?');
lambda=input('Enter positive "lambda"?');
eta1=input('Enter positive "eta1"?');
eta2=input('Enter positive "eta2"?');
P=input('Enter positive "P"?');
%% Feasible Area
x = -1:P;m = 0; c = eta2; y = m * x + c;
plot(x, y, 'black')
y = -1:P; m = 0; c = eta1; y = m * x + c;
plot(y, x, 'black')
eta1=min (eta1,P); eta2=min (eta2,P);
if eta1+eta2<P
X=[0 0 eta1 eta1]; Y=[0 eta2 eta2 0];
fill(X,Y,[0.85 0.85 0.85]);
else
X=[0 0 P-eta2 eta1 eta1]; Y=[0 eta2 eta2 P-eta1 0];
fill(X,Y,[0.85 0.85 0.85]); axis([-1 P -1 P])
end
X=[0 0]; Y=[0 P];
line(X,Y,'Color','black')
hold on
line(Y,X,'Color','black')
g = @(x,y) x+y-P;
gp =fimplicit(g,[0 P 0 P], 'black')
f = @(x,y) log((1+alpha1*x./(1+alpha2*y))) -lambda*log((1+beta1*x./(1+beta2*y)));
fp =fimplicit(f,[-1 P -1 P], '-')
hold on
grid on
For alpha1=1 , alpha2=0.2, beta1=1,beta2=2, lambda=2, eta1=3,eta2=4, P=2
Many Thanks in advance

댓글 수: 3

Jan
Jan 2021년 3월 7일
편집: Jan 2021년 3월 8일
Please remember, that all questions are urgent for the asking persons. Therefore it is polite not to claim, that a question is more urgent than others.
If the answer is important for you, care for asking a clear and unique question. What does "find intersections in this plot without mouse(Using code)" exactly mean? What kind of "intersection" is meant and how would you determine it with the mouse?
Firstly , If you read my request carefully, I have not claimed that my question is more unrgent than others. Secondly, you can run ginput function and then select your desired coordinate from lines by using mouse.
Thanks,
Some members of this forum react allergic to the term "urgent", see e.g. https://www.mathworks.com/matlabcentral/answers/29922-why-your-question-is-not-urgent-or-an-emergency .
You are drawing some objects. I cannot guess between which of these obejcts you want to locate the interection. The more the readers have to guess, the longer takes it to answer.

댓글을 달려면 로그인하십시오.

답변 (1개)

Gautam
Gautam 2025년 1월 2일
편집: Gautam 2025년 1월 2일
Hello Hossein,
If you want to find the point of intersection of any tow lines programmatically, you can do so following the steps below:
  1. Create handles to the line objects for which you want to find the intersection point, like:
line1 = line(X,Y,'Color','black');
line2 = line(Y,X,'Color','black');
2. Use the “XData” and “YData” properties of the line objects to find the point of intersection:
interX = line1.XData(line1.XData == line2.XData);>>interY = line1.YData(line1.YData == line2.YData);
3. You can show the point of intersection on the plot using
plot(interX, interY, 'rO', 'MarkerSize',6, 'MarkerFaceColor','red')
Plotting the point of intersection of the lines produces the following graph
You can use the same steps to find the point of intersection of any two lines in your code

댓글 수: 1

Comparing the XData and YData properties of two lines will generally not work.
X = [0 3];
Y = [1 2];
line1 = line(X,Y,'Color','black');
line2 = line(Y,X,'Color','black');
interX = line1.XData(line1.XData == line2.XData);
interY = line1.YData(line1.YData == line2.YData);
plot(interX, interY, 'rO', 'MarkerSize',6, 'MarkerFaceColor','red')
There is no-place that the XData from the one line happens to be exactly the XData from the other line.
The XData property does not interpolate. The result is not the same as
cla
X = 0:.1:3;
Y = linspace(1,2,numel(X));
line1 = line(X,Y,'Color','black');
line2 = line(Y,X,'Color','black');
interX = line1.XData(line1.XData == line2.XData);
interY = line1.YData(line1.YData == line2.YData);
plot(interX, interY, 'rO', 'MarkerSize',6, 'MarkerFaceColor','red')

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Graphics Performance에 대해 자세히 알아보기

질문:

2021년 3월 7일

댓글:

2025년 1월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by