How to solve a plotting problem regarding straight lines
1 次查看(过去 30 天)
显示 更早的评论
How can I make the two lines meet in their intersection point as shown in the figure below ?
(I want to obtain the two lines that I've drawn using red dots!)
clc ;clear all; close all;
%Profilo
gamma = 1.4;
xdorso = [0 0.7 1]; xventre = [0 0.45 1];
ydorso = [0 0.03 0]; yventre = [0 -0.05 0];
delta1 = atand(0.03/0.44);
delta2 = atand(0.05/0.45);
delta3 = atand(0.03/0.56);
delta4 = atand(0.05/0.55);
n = 1000;
x = linspace(0,1,n);
alfa = -8:2:8;
deviazionedorso = delta1 + abs(alfa(1:4));
deviazioneventre = delta2 + alfa(5:end);
mach1 = 1.01:0.001:1.6;
lunghezza = length(mach1);
massimo = mach1;
for i = 1:lunghezza
m1 = mach1(i);
epsmin = asin(1/m1)*57.3;
eps = linspace(epsmin,90,30);
delta = abaco(eps,m1,gamma);
massimo(i)= max(delta);
figure(1)
plot(eps,delta);
hold on
end
machcriticodorso = deviazionedorso;
for i = 1:length(deviazionedorso)
calcolod = deviazionedorso(i);
for j = 1:lunghezza
if abs(massimo(j)-calcolod)<0.1
machcriticodorso(i) = mach1(j);
end
end
end
machcriticoventre = deviazioneventre;
for i = 1:length(deviazioneventre)
calcolov = deviazioneventre(i);
for j = 1:lunghezza
if abs(massimo(j)-calcolov)<0.1
machcriticoventre(i) = mach1(j);
end
end
end
machcriticosuperiore = [machcriticodorso machcriticoventre];
figure(4);
plot(alfa,machcriticosuperiore,'k-o');
xlabel('\alpha'); ylabel('M_{cr_{sup}}');
axis([-8 8 1 1.6])
0 个评论
采纳的回答
Turlough Hughes
2019-12-1
We don't really need all that code to answer the question. It would be much more preferable to just post some sample data. Anyway, I've tried to replicate your data as follows:
x=linspace(-8,8,9);
y=[linspace(0.5,0.28,4) linspace(0.29,0.59,5)];
Where x and y correspond to the data in alfa,machcriticosuperiore.
You could use a linear fit to the "two lines" and then solve for the point of intersection as follows:
idx=x<=-1;
l1=polyfit(x(idx),y(idx),1); % l1 is coefficient m, c, of a linear fit to the data
l2=polyfit(x(~idx),y(~idx),1);
xi=(l2(2)-l1(2))/(l1(1)-l2(1)); % When y of line 1 = y of line 2, you get xi=(c2-c1)/(m1-m2)
yi=l1(1)*xi+l1(2);
plot(x,y,'ok')
hold on, plot(xi,yi,'or')
You could also insert the intersection point into your original data and then plot with the line:
x=[x(idx) xi x(~idx)];
y=[y(idx) yi y(~idx)];
xlabel('\alpha'); ylabel('M_{cr_{sup}}');
plot(x,y,'-ok');
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!