Grabbing number from array to calculate the numerical derivative
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Mateusz Brzezinski
el 17 de Feb. de 2020
Comentada: Mateusz Brzezinski
el 18 de Feb. de 2020
Hello,
I ma looking for solution that will allow me to calculate a derative (in numerical way) from data from array.
I have an array caled DataOutput it's defined as:
DataOutput = zeros(length(phiAStart:phiAStep:phiAEnd),30);
where :
phiAStart:phiAStep:phiAEnd
are defined by a user (as input)
In this array, I have two columns that I would like to further work with. In column 1 I have "x" and in column 26 I have a "y"... where y=f(x) and x value is incremented by loop function:
for x=phiAStart:phiAStep:phiAEnd
...
end
Now what I would like to do is calculate a derivative and store it in another array (or even in the same if its possible). For calculation I would like to use simple formula:
f'(n)=((y(n+1))-(y(n-1)))/((x(n+1))-(x(n-1)))
For clarification this is how it's done in excel sheet:
I am assuming that I will need another for loop outside of the previous one but I am not sure how I should define a formula for this sort of equation (especially how to define new vectors).
I would be thankful for any idea.
0 comentarios
Respuesta aceptada
James Tursa
el 17 de Feb. de 2020
Editada: James Tursa
el 17 de Feb. de 2020
For the version you post, see the diff( ) function along with element-wise divide. E.g.,
diff(y) ./ diff(x)
If that doesn't work well enough for you, you could explore central difference formula versions, or perhaps some type of curve fit.
2 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Matrix Indexing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!