繁体   English   中英

直线与曲线的交点 Matlab

[英]Intersection of line and curve Matlab

好吧,最近又出现了另一个问题。 我有一组代表曲线和一条线,我用 line() 函数绘制。 到目前为止,我的代码是:

clc, clear all, close all;

n = 800/1500;
I = [ 0 1.1 4 9.5 15.3 19.5 23.1 26 28.2 30.8 33.3 35.9];
E_up = [ 5.8 10.5 28 60.3 85.5 100.3 108 113.2 117 120.5 123.5 126];
E_up = E_up./n;
Iw = [ 34 31.5 28.2 23.9 19.9 16.1 13 8.1 3.5 1.2 0 NaN];
E_down = [124.6 122.5 118.8 112.2 103.9 93.1 81.6 59.1 29.6 14.5 9.5 NaN];
E_down = E_down./n;


x_est = I;
y_est = spline(Iw,E_down,x_est)
A(:,1)= E_up
A(:,2) = y_est

ma = mean(A,2)

% figure()
% hold all
% % plot(x_est,y_est,'ro')
% plot(I,E_up,'b-',Iw,E_down,'g-')
% plot(I,ma,'r')
% grid on
% legend('up','down','mean')

%dane_znamionowe

clc, clear all, close all;

%data_entry
n = 800/1500;
I = [ 0 1.1 4 9.5 15.3 19.5 23.1 26 28.2 30.8 33.3 35.9];
E_up = [ 5.8 10.5 28 60.3 85.5 100.3 108 113.2 117 120.5 123.5 126];
E_up = E_up./n; %rescalling_EMF
Iw = [ 34 31.5 28.2 23.9 19.9 16.1 13 8.1 3.5 1.2 0 NaN];
E_down = [124.6 122.5 118.8 112.2 103.9 93.1 81.6 59.1 29.6 14.5 9.5 NaN];
E_down = E_down./n; %rescalling_EMF
Un = 220;
In = 28.8;
wn = 1500;
wmax = 3000;
P = 5.5e3;
Rs = 15.8/25;

%interpolation
x_est = I;
y_est = spline(Iw,E_down,x_est);

%mean_values
A(:,1)= E_up;
A(:,2) = y_est;
ma = mean(A,2);

%party_Xd
figure()
[ax,h1,h2] = plotyy(I+30,wn,I,ma,'plot','plot');
set(ax(1),'ylim',[0 3000],'ytick',[1500  3000]);
set(ax(2),'ylim',[0 300],'ytick',[100 200 300]);
hold(ax(1))
hold(ax(2))

%stable_parts
set(ax,'NextPlot','add')
plot(ax(2),I,ma,'b')
plot(ax(2),0,Un,'m*')
i2 = 0:0.01:70;
plot(ax(2),i2,Un-(i2*Rs),'m--')
iin = 0:1:300;
plot(ax(2),In,iin,'g-')
plot(ax(1),i2,wn,'k-','linewidth',8)
plot(ax(1),28.8,1500,'g*')

%loop
p1x = [35 45 55 65];

for ii = 1 :length(p1x)
    x11 = p1x(ii);
    y11 = 0;
    x21 = In;
    y21 = wn;
    x1 = [35 45 55 65];
    y1 = [0 0 0 0];
    x2 = [In In In In];
    y2 = [wn wn wn wn];
    slope = (y21-y11)/(x21-x11);
    xLeft = 0; 
    yLeft = slope * (xLeft - x11) + y11;
    xRight = 70; 
    yRight = slope * (xRight - x11) + y11;
    plot(ax(2),x11,0,'r.')
    a1 = line([xLeft, xRight], [yLeft, yRight], 'Color', 'c');

    x0 = (max(min(x1),min(x2))+min(max(x1),max(x2)))/2;
    fun1 = @(x) interp1(x1,y1,x,'linear');
    fun2 = @(x) interp1(x2,y2,x,'linear');
    difffun = @(x) fun1(x)-fun2(x);
    crossing = fzero(difffun,x0); %crossing x coordinate
    crossval = fun1(crossing);
end

我的图看起来像这样,相当不错。但我需要找到青色线和蓝色曲线的交点。

在此处输入图片说明

基于我对类似问题的解决方案的答案:

%dummy input
x1=[0 1 2 3]; 
y1=[1 4 2 0];
x2=[-1 3 4 5];
y2=[-1 2 5 3];

x0 = (max(min(x1),min(x2))+min(max(x1),max(x2)))/2;
fun1 = @(x) interp1(x1,y1,x,'linear','extrap');
fun2 = @(x) interp1(x2,y2,x,'linear','extrap');
difffun = @(x) fun1(x)-fun2(x);

crossing = fzero(difffun,x0); %crossing x coordinate
crossval = fun1(crossing); %substitute either function at crossing point

plot(x1,y1,'b-',x2,y2,'r-',crossing,crossval,'ks');
legend('line1','line2','crossover','location','nw');

之后,您的交叉点由[crossing, crossval]

结果:

结果

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM