How to find the gradient of plotted values?

25 visualizaciones (últimos 30 días)
France Gian
France Gian el 13 de Dic. de 2023
Respondida: Hassaan el 5 de En. de 2024

So, I'm trying to find the rate of climb against the velocity.

Both of these variables are 1 x 100 vectors.

rate of climb = v.*(T-D)./w

where w is a constant. t,d and v are all arrays of 1 x 100 row vectors. I was wondering ways to find the derivative at the local maximum. Examples would be appreciated.

Respuestas (3)

madhan ravi
madhan ravi el 4 de En. de 2024
Editada: madhan ravi el 4 de En. de 2024
Derivative at the local maximum is zero.
You could find the gradient of a variable using
doc gradient

Star Strider
Star Strider el 4 de En. de 2024
Use the gradient function to calculate the numerical gradient/derivative —
Fs = 100;
L = 60;
t = linspace(0, Fs*L, Fs*L+1)/Fs; % Time Vector
s = sin(2*pi*t/10) .* exp(-(t-30).^2*0.01); % Signal Vector
dsdt = gradient(s, t); % Gradient (Derivative)
figure
plot(t, s, 'DisplayName','Signal')
hold on
plot(t, dsdt, 'DisplayName','Derivative')
hold off
grid
legend('Location','best')
.

Hassaan
Hassaan el 5 de En. de 2024
% Dummy values for T, D, and v
w = 5000; % Constant weight
v = linspace(100, 300, 100); % Velocity vector ranging from 100 to 300 m/s
T = 2000 + 100 * cos(linspace(0, 2*pi, 100)); % Thrust vector as a function of v
D = 1500 + 50 * sin(linspace(0, 2*pi, 100)); % Drag vector as a function of v
% Calculate the rate of climb
rate_of_climb = v .* (T - D) / w;
% Find the local maxima of the rate of climb
[peaks, locs] = findpeaks(rate_of_climb);
% Assuming uniform spacing in your velocity vector
% Calculate the numerical derivative using the gradient function
dv = mean(diff(v)); % The mean difference between velocity points
derivative_roc = gradient(rate_of_climb, dv);
% Find the derivative at the local maxima
derivative_at_maxima = derivative_roc(locs);
% Display the results
disp('Velocity at local maxima:');
Velocity at local maxima:
disp(v(locs));
140.4040
disp('Rate of climb at local maxima:');
Rate of climb at local maxima:
disp(peaks);
13.5335
disp('Derivative of rate of climb at local maxima:');
Derivative of rate of climb at local maxima:
disp(derivative_at_maxima);
-8.7495e-04
% For visualization, plot the rate of climb and mark the local maxima
figure;
plot(v, rate_of_climb);
hold on;
plot(v(locs), peaks, 'ro');
xlabel('Velocity (m/s)');
ylabel('Rate of Climb (m/s)');
title('Rate of Climb vs. Velocity');
legend('Rate of Climb', 'Local Maxima');
grid on;
hold off;
rate_of_climb is calculated using the given formula.
findpeaks is used to locate the local maxima in the rate of climb.
gradient function is used to numerically approximate the derivative of the rate of climb with respect to velocity.
------------------------------------------------------------------------------------------------------------------------------------------------
If you find the solution helpful and it resolves your issue, it would be greatly appreciated if you could accept the answer. Also, leaving an upvote and a comment are also wonderful ways to provide feedback.
Professional Interests
  • Technical Services and Consulting
  • Embedded Systems | Firmware Developement | Simulations
  • Electrical and Electronics Engineering

Categorías

Más información sobre Spectral Measurements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by