How to find the gradient of plotted values?

4 ビュー (過去 30 日間)
France Gian
France Gian 2023 年 12 月 13 日
回答済み: Hassaan 2024 年 1 月 5 日

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.

回答 (3 件)

madhan ravi
madhan ravi 2024 年 1 月 4 日
編集済み: madhan ravi 2024 年 1 月 4 日
Derivative at the local maximum is zero.
You could find the gradient of a variable using
doc gradient

Star Strider
Star Strider 2024 年 1 月 4 日
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 2024 年 1 月 5 日
% 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

カテゴリ

Help Center および File ExchangeParametric Spectral Estimation についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by