plotting half an ellipse, a linear line and the interceptions between

조회 수: 6 (최근 30일)
Yuval
Yuval 2024년 6월 21일
댓글: Yuval 2024년 6월 22일
Hi all
i would like to plot an ellipse that will grow in a for loop.
i also have a linear line that doesnt change.
i would like to find the interceptions between the linear line and the ongrowing ellipses.
the code looks like that:
x1 = p0/OCR:0.1:x_int;
yeta=+3*x1-3*p;
t=0:0.01:pi;
plot(p0/2+p0/2*cos(t),p0/2*M*sin(t), 'k')
and then i change the p0 value with a for loop, giving me a bigger ellipse.
plot(p(i),q(i),'ko','MarkerFaceColor', 'k', 'MarkerSize', 4)
how do i shoe the interceptions, and not the p value? (attached pic, the 1st subplot)

답변 (1개)

Hassaan
Hassaan 2024년 6월 21일
% Parameters
p0 = 400; % Initial p0 value
M = 1.5; % Ratio for the ellipse equation
% Linear line equation
x1 = 400:0.1:600;
yeta = 3 * x1 - 1200;
% Plot the static linear line
figure;
subplot(2, 2, 1);
plot(x1, yeta, 'r', 'LineWidth', 1.5);
hold on;
% Initial plot for the first ellipse
t = 0:0.01:pi;
p_values = p0/2 + p0/2 * cos(t);
q_values = p0/2 * M * sin(t);
plot(p_values, q_values, 'k', 'LineWidth', 1.5);
hold on;
% Plot ellipse and calculate intersections in a loop
for k = 1:5
p0 = p0 + 10; % Increase p0 for the growing ellipse
p_values = p0/2 + p0/2 * cos(t);
q_values = p0/2 * M * sin(t);
% Plot the growing ellipse
plot(p_values, q_values, 'k', 'LineWidth', 1.5);
% Find intersections
for i = 1:length(x1)
% Intersection condition
idx = find(abs(p_values - x1(i)) < 1e-1 & abs(q_values - yeta(i)) < 1e-1);
if ~isempty(idx)
plot(p_values(idx), q_values(idx), 'ko', 'MarkerFaceColor', 'k', 'MarkerSize', 4);
end
end
end
% Set axis properties
axis equal;
xlim([350 650]);
ylim([0 250]);
xlabel('p [kPa]');
ylabel('q [kPa]');
title('Intersections of Ellipses and Linear Line');
grid on;
hold off;
  댓글 수: 2
Yuval
Yuval 2024년 6월 21일
편집: Yuval 2024년 6월 21일
Hassan thanks.
in your code, only the first line gets a markercolor, why? and how can we show on every ellipse?
is it possible to do so with an array? so the interceptions will help in other subplots as well?
Yuval
Yuval 2024년 6월 22일
UPDATE
i used the code you suggested, im not recieving all interceptions, please advise

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

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

제품


릴리스

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by