How can I get the maximum slope of a curve?
68 次查看(过去 30 天)
显示 更早的评论
How can I find the initial maximum slope of the below curve?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1326625/image.jpeg)
0 个评论
采纳的回答
Star Strider
2023-3-16
The file is not a .mat file.
That problem aside, I would calculate the instantaneous slope as:
m = gradient(Cell_Voltage_1) ./ gradient(Cell_Time_1);
and then find the maximum of ‘m’ in the region-of-interest.
.
3 个评论
Star Strider
2023-3-17
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 —
LD1 = load(websave('Cell_Time_1','https://www.mathworks.com/matlabcentral/answers/uploaded_files/1327165/Cell_Time_1.mat'));
LD2 = load(websave('Cell_Voltage_1','https://www.mathworks.com/matlabcentral/answers/uploaded_files/1327170/Cell_Voltage_1.mat'));
Cell_Time_1 = LD1.Cell_Time_1;
Cell_Voltage_1 = LD2.Cell_Voltage_1;
m = gradient(Cell_Voltage_1) ./ gradient(Cell_Time_1);
FirstSlope = m(1) % Calculated By 'gradient'
Theta_FirstSlope = tan(m(1)) % Calculated By 'gradient'
[mmn,mnidx] = min(m) % Minimum Gradient Slope & Index
Time_MinSlope = Cell_Time_1(mnidx) % Time At Minimum Slope
Voltage_MinSlope = Cell_Voltage_1(mnidx) % Voltage At Minimum Slope
Theta_MinSlope = tan(mmn) % Minimum Theta
% 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_theta = tan(m_max)
% % 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
2023-3-25
As always, my pleasure!
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:
m = gradient(Cell_Voltage_1) ./ gradient(Cell_Time_1); % Numerical Derivative
[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.
.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Optimization Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!