# How can I get the maximum slope of a curve?

50 visualizzazioni (ultimi 30 giorni)
Bob il 16 Mar 2023
Commentato: Star Strider il 25 Mar 2023
How can I find the initial maximum slope of the below curve?
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposta accettata

Star Strider il 16 Mar 2023
The file is not a .mat file.
That problem aside, I would calculate the instantaneous slope as:
and then find the maximum of ‘m’ in the region-of-interest.
.
##### 3 CommentiMostra 1 commento meno recenteNascondi 1 commento meno recente
Star Strider il 17 Mar 2023
I am not certain how you want to define the slope. I plotted them here at every value of ‘Cell_Time_1’ on a yyaxis plot to make them more easioly visible. Because of the nature of the central difference calculation (Algorithms), the slope calculated by the gradient function returns a much different value than ‘m_max’ and of course also for θ. I generally use the gradient approach to calculate the slopes, largely because it tends to be more consistent. I defer to you to determine which of those to use.
My analysis —
Cell_Time_1 = LD1.Cell_Time_1;
Cell_Voltage_1 = LD2.Cell_Voltage_1;
FirstSlope = m(1) % Calculated By 'gradient'
FirstSlope = -4.4261e-05
Theta_FirstSlope = tan(m(1)) % Calculated By 'gradient'
Theta_FirstSlope = -4.4261e-05
[mmn,mnidx] = min(m) % Minimum Gradient Slope & Index
mmn = -0.0065
mnidx = 3
Time_MinSlope = Cell_Time_1(mnidx) % Time At Minimum Slope
Time_MinSlope = 35.7030
Voltage_MinSlope = Cell_Voltage_1(mnidx) % Voltage At Minimum Slope
Voltage_MinSlope = 3.9749
Theta_MinSlope = tan(mmn) % Minimum Theta
Theta_MinSlope = -0.0065
% Initial Maximum Slope of the Voltage Characteristic curve in the process
% of Discharge.
m_max = ((Cell_Time_1(2) - Cell_Time_1(1)) / (Cell_Voltage_1(2) - Cell_Voltage_1(1)))
m_max = -2.2593e+04
m_theta = tan(m_max)
m_theta = 1.4152
% % Results
% figure; hold on;
% plot(Cell_Time_1, Cell_Voltage_1, 'LineWidth', 2);
% plot(m, 'LineWidth', 2);
% title('Discharging Voltage Curve');
% legend('Cell (1st Cycle)','Slopes');
% xlabel('Time (Seconds)');
% ylabel('Voltage (V)');
% axis auto;
% grid on;
% Results
figure
yyaxis left
plot(Cell_Time_1, Cell_Voltage_1, 'LineWidth', 2)
ylabel('Voltage (V)');
yyaxis right
plot(Cell_Time_1, m, 'LineWidth', 2);
ylabel('Slope')
title('Discharging Voltage Curve');
legend('Cell (1st Cycle)','Slopes', 'Location','best');
xlabel('Time (Seconds)');
% axis auto;
grid on;
hxl = xline(Time_MinSlope, '-k', 'Minimum Slope Time', 'DisplayName','Minimum Slope Time');
hxl.LabelVerticalAlignment = 'middle';
.
Star Strider il 25 Mar 2023
As always, my pleasure!
With respect to your edited Comment, that depends on what you want and how you want to define it.
If you want the initial slope, then this:
m_max = ((Cell_Voltage_1(2) - Cell_Voltage_1(1)) / (Cell_Time_1(2) - Cell_Time_1(1)));
is correct using that specific method of calculating it.
If you want the maximum slope (actually minimum in this instance, since the slopes are negative), then this:
[mmn,mnidx] = min(m) % Minimum Gradient Slope & Index
is correct.
The initial slope derived from the gradient calculation:
FirstSlope = m(1) % Calculated By 'gradient'
is different from the the directly-calculated initial slope ‘m_max’ because the calculations themselves are different.
Any of them can be used in the ‘m_theta’ calculation.
I prefer to use the gradient-based slope calculations because they tend to be more consistent, however the ‘true’ slope here depends on how you choose to define it. Since these are your data, that is your call.
.

Accedi per commentare.

### Categorie

Scopri di più su Optimization Toolbox 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!

Translated by