How to find the intersection of two curves (2 points of intersection)
5 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Rhiannon Elliott
il 3 Feb 2021
Commentato: Star Strider
il 4 Feb 2021
I have a piece of code that I eventually will turn into a function to find the minimum and maximum velocities an aircraft can fly at, in relation to the power available from the engine, and the power required to fly at those conditions. In the figure from this code, there is a flat line that represents the power available, and a curved line that represents the power required.
Is there a simple way to output the intersections of these lines? Ideally so further down the line this can all be used as a function?
Appreciate all the help I can get!
close all
clear
clc
%Code to determine the maximum and minimum speeds at a given altitude for
%the Cessna 172P
H=0; %Eventually this will become an input in a function where the
% user just call the function and recieve the miniumum and maximum velocities for a given altitude
%Constants of the aircraft
S = 16.16499443; %Wing area [m^2]
g = 9.81; %acceleration due to gravity [ms^-2]
W = 887.0748299*g; %Weight of the aircraft [kgf]
C_D0 = 0.026; %Zero lift drag coefficient
K = 0.121; %Drag constant
%Range of velocities we wish to investigate [Mach]
M = linspace(0,0.8,100);
[~,rho,~,a]=atmosProperties(H,0,0); %Density and speed of sound at given altitude [kgm^-3] [ms^-1]
[~,maxPA]=getPAmax(H); %Maximum power available at given altitude [W]
V = M.*a; %Velocity in [ms^-1]
C_L = (2./rho).*(W./S).*(1./(V.^2)); %Lift coefficient at given altitude
C_D = C_D0 + K .* C_L.^2; %Drag coefficient at given altitude
P_req = 0.5 .* rho .* V.^3 .* S .* C_D; %Power required curve
b = [maxPA, maxPA]; %B and c are used to plot a line that corresponds to the maximum power available
c = [0,272.235190420871];
%Goal of the figure is to find the intersections of the power available curve (flat line) and the power required curve (curved line)
%Legends will be added later on
plot (V, P_req);
hold on
plot (c, b);
xlabel("TAS [ms^-1]");
ylabel("Power reequired (W)")
0 Commenti
Risposta accettata
Star Strider
il 3 Feb 2021
I can’t run your code, since I don’t have the functions.
As a general rule however, it is straightforward to find the intersections between two curves, even if the functions to calculate them do not exist.
Try this with your vectors:
x = linspace(0, 10); % Independent Variable
y1 = 10 - (x-5).^2; % Dependent Variable #1
y2 = 5*sin(2*pi*x/5); % Dependent Variable #1
curvdif = y1 - y2; % Subtract Curves
intidx = find(diff(sign(curvdif))); % Approximate Indices Of Zero-Crossings
for k = 1:numel(intidx)
idxrng = [max(1,intidx(k)-1):min(numel(x),intidx(k)+1)]; % Index Range For Interpolation
xv(k) = interp1(curvdif(idxrng), x(idxrng), 0); % Interpolate To Estimate ‘x’ At Intersection
yv(k) = interp1(x(idxrng),y1(idxrng), xv(k)); % Interpolate To Estimate ‘y’ At Intersection
end
figure
plot(x, y1, x, y2)
hold on
plot(xv, yv, 'pg', 'MarkerSize',15)
hold off
grid
legend('y_1', 'y_2', 'Intersections', 'Location','S')
I have many happy memories of flying C172s! Have fun!
4 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Surface and Mesh Plots in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
