# MATLAB: Find intersection between two llines

MATLABplotplotting

Hi everyone,
I need to find the exact intersection between the vectors m_compressor and mass_flow_corrected.
clearclcclose all%% Gas propertiesk = 1.4;          %Gas constant ratio, cp/cv()R = 287.05;       %Ideal gas constant [J/Kg*K]p01 = 1e5;        %Compressor inlet pressure(Pa)T01 = 303.35;     %Compressor inlet temperature(K)cp = 1005;        %Specific heat capacity for constant pressure, property of gas(J/(kg*K))ro1 = 1.15;       %Gas density(kg/m^3)%% Turbine's parametersA_eff = .0089;     %[m^2]A_0 = A_eff/.6;dx = 0.001;E_R = [1:dx:4]; %Expansion ratioT_3 = 1173.15;     %Discharge temperature [K]%% Compressor's parametersU = 164.17; %[m/s]Ac = 0.0026; %[m^2]m_c_adim = 0.273675009794891; %adimensional mass flow from Greitzer steady-statem_c = m_c_adim*[ro1*Ac*100*(T01^0.5)]; %actual compressor's mass flowp2 = 2.591609008885050*p01;P_R = (p2)/(0.5*ro1*(U^2));%% m_compressor = m_c*ones(1,length(E_R));mass_flow = A_eff.*((k./R).^0.5).*((1./E_R).^(1/k)).*(((2./k-1).*(1-(1./E_R).^((k-1)./k))).*0.5);mass_flow_corrected = (mass_flow).*p01;%% Plotsfigure()plot(E_R,mass_flow_corrected,...    E_R,m_compressor)grid ongrid minorxlabel('ER')legend('turbine','compressor')ylabel('corrected mass flow')title('ER vs mass flow')any (mass_flow_corrected == m_compressor)intersection = find(mass_flow_corrected == m_compressor);x_ER = E_R(intersection)y_ER = mass_flow_corrected(intersection)
I am trying as I read on the forum, but it's not working, I wonder if there is any other way of dooing so.

x_ER = interp1(mass_flow_corrected - m_compressor, E_R, 0);y_ER = A_eff.*((k./R).^0.5).*((1./x_ER).^(1/k)).*(((2./k-1).*(1-(1./x_ER).^((k-1)./k))).*0.5) * p01;
%% Gas propertiesk = 1.4;          %Gas constant ratio, cp/cv()R = 287.05;       %Ideal gas constant [J/Kg*K]p01 = 1e5;        %Compressor inlet pressure(Pa)T01 = 303.35;     %Compressor inlet temperature(K)cp = 1005;        %Specific heat capacity for constant pressure, property of gas(J/(kg*K))ro1 = 1.15;       %Gas density(kg/m^3)%% Turbine's parametersA_eff = .0089;     %[m^2]A_0 = A_eff/.6;dx = 0.001;E_R = [1:dx:4]; %Expansion ratioT_3 = 1173.15;     %Discharge temperature [K]%% Compressor's parametersU = 164.17; %[m/s]Ac = 0.0026; %[m^2]m_c_adim = 0.273675009794891; %adimensional mass flow from Greitzer steady-statem_c = m_c_adim*[ro1*Ac*100*(T01^0.5)]; %actual compressor's mass flowp2 = 2.591609008885050*p01;P_R = (p2)/(0.5*ro1*(U^2));%% m_compressor = m_c*ones(1,length(E_R));mass_flow = A_eff.*((k./R).^0.5).*((1./E_R).^(1/k)).*(((2./k-1).*(1-(1./E_R).^((k-1)./k))).*0.5);mass_flow_corrected = (mass_flow).*p01;%% Plotsfigure()plot(E_R,mass_flow_corrected,...    E_R,m_compressor)grid ongrid minorxlabel('ER')legend('turbine','compressor')ylabel('corrected mass flow')title('ER vs mass flow')x_ER = interp1(mass_flow_corrected - m_compressor, E_R, 0);y_ER = A_eff.*((k./R).^0.5).*((1./x_ER).^(1/k)).*(((2./k-1).*(1-(1./x_ER).^((k-1)./k))).*0.5) * p01;hold onplot(x_ER, y_ER, 'pg')hold offtext(x_ER, y_ER, sprintf('\\uparrow\nIntersection:\nx\\_ER = %.3f\ny\\_ER = %.3f', x_ER, y_ER), 'HorizontalAlignment','left', 'VerticalAlignment','top')