How to find the gradient of plotted values?
조회 수: 25 (최근 30일)
이전 댓글 표시
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.
댓글 수: 0
답변 (3개)
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
댓글 수: 0
Star Strider
2024년 1월 4일
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')
.
댓글 수: 0
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:');
disp(v(locs));
disp('Rate of climb at local maxima:');
disp(peaks);
disp('Derivative of rate of climb at local maxima:');
disp(derivative_at_maxima);
% 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
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Spectral Measurements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!