Find the intersection of two lines with multiple intersections.
Show older comments
Hi,
I am trying to find the intersection of these two lines and plot both. I have tried fzero() and fiind(), but they are both not working.
% Basic Variables
k_prime = 1000; np = .85; P = 750; rho = 1.225; S = 25; W = 1600*25; Cl_max = 1.5; k = .05;
Cdo = .025; Cd = Cdo + .05*(Cl_max^2); W_S = 1600; V = 0:200;
% Equations
Pa = k_prime * np * P;
Pr = (.5 * rho * S * Cdo * V.^3) + ((2*k*W^2)./(rho*S*V));
% Plotting
figure; ylim([0 10*10^5]); yline(Pa); hold on;
plot(V,Pr,'--'); hold on; legend("Available Power", "Required Power");
1 Comment
Ankit
on 2 Sep 2022
Try this file from file exchange: Intersection of Two Lines (line_intersection) - File Exchange - MATLAB Central (mathworks.com)
Answers (2)
% Basic Variables
k_prime = 1000; np = .85; P = 750; rho = 1.225; S = 25; W = 1600*25; Cl_max = 1.5; k = .05;
Cdo = .025; Cd = Cdo + .05*(Cl_max^2); W_S = 1600; V = 0:200;
% Equations
Pa = k_prime * np * P;
Pr = (.5 * rho * S * Cdo * V.^3) + ((2*k*W^2)./(rho*S*V));
% Plotting
figure;
ylim([0 10*10^5]);
yline(Pa); hold on;
plot(V,Pr,'--');
legend("Available Power", "Required Power");
% Find intersection
x = linspace(min(V),max(V),200) ;
y = Pa*ones(size(x)) ;
P = InterX([x;y],[V;Pr]) ;
plot(P(1,:),P(2,:),'*r')

% Basic Variables
k_prime = 1000; np = .85; P = 750; rho = 1.225; S = 25; W = 1600*25; Cl_max = 1.5; k = .05;
Cdo = .025; Cd = Cdo + .05*(Cl_max^2); W_S = 1600; V = 0:200;
% Equations
Pa = k_prime * np * P;
Pr = (.5 * rho * S * Cdo * V.^3) + ((2*k*W^2)./(rho*S*V));
% Plotting
figure; ylim([0 10*10^5]); yline(Pa); hold on;
plot(V,Pr,'--'); hold on; legend("Available Power", "Required Power");
fun=@(V)(.5 * rho * S * Cdo * V.^3) + ((2*k*W^2)./(rho*S*V))-Pa;
V1=fzero(fun,20)
V2=fzero(fun,120)
plot([V1 V2],[Pa Pa],'or')
Categories
Find more on Develop Apps Using App Designer in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!