Finding the gradient of a slope
34 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I have this graph and I need to find the cooling rate.
I need to split the curve into smaller lines and then find the gradient of each line. Then I need to find the average of each gradient up to approximately 25 degrees to find the cooling rate. I have a lot of data to go through.
Can anyone help me please?
Thanks in advance!
1 Commento
John D'Errico
il 18 Apr 2020
Modificato: John D'Errico
il 18 Apr 2020
That is what computers are good at. You use loops, and let the computer do the work. Of course, it looks like you managed to create zillions of variables all with numbered names. Next time, don't do that, as then you end up in a situation where you have a lot of work to do. Instead, use arrays. Then you can just write a loop.
If you want a suggestion, put all of your data into one array, even if that requires using a cell array, and some typing up front. Then just use a loop.
Risposte (2)
Ameer Hamza
il 18 Apr 2020
For example
cooling_rate = mean(gradient(time,temperature))
2 Commenti
Ameer Hamza
il 20 Apr 2020
Diane, It is not because if a large dataset. It will happen if there is a vertical line in your dataset. For example, consider these small vectors
x = [0 1 1 1 2];
y = [0 1 2 3 4];
g = gradient(y,x);
but the gradient still become infinity at some points
g =
1 2 Inf 2 1
Star Strider
il 20 Apr 2020
The gradient function second argument is the uniform spacing constant (in the documentation, ‘h’, assumed to be 1 by default if not provided).
Regardless of the spacing of the independent variable vector, and whether it is uniform or not, dividing the gradient of the dependent variable by the gradient of the independent variable will give the correct result for the numerical derivative of the dependent variable with respect to the independent variable.
For example, using the ‘fig.fig’ file:
F = openfig('fig.fig');
Lines = findobj(F, 'Type','Line'); % Find ‘Line’ Objects
for k = 1:numel(Lines)
x{k} = Lines(k).XData;
y{k} = Lines(k).YData;
dydx{k} = gradient(y{k}) ./ gradient(x{k}); % Iterate & Calculate Gradient
end
figure
hold on
for k = 1:numel(dydx)
plot(x{k}, y{k}, '-b', x{k}, dydx{k}*10+10, '--c') % Plot Data & Numerical Derivatives
end
hold off
grid
hl = legend('Data', '$\frac{dy}{dx}$');
hl.Interpreter = 'latex';
There is only one 'Line' object in this file, however the code is written to accommodate several. (This code will require minor modifications to use with data that are not extracted from one or more figures.)
I do not know if this will result in infinite results, since I do not have the data that generated those results in the current code.
.
0 Commenti
Vedere anche
Categorie
Scopri di più su Spline Postprocessing 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!