Grabbing number from array to calculate the numerical derivative
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Mateusz Brzezinski
am 17 Feb. 2020
Kommentiert: Mateusz Brzezinski
am 18 Feb. 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 Kommentare
Akzeptierte Antwort
James Tursa
am 17 Feb. 2020
Bearbeitet: James Tursa
am 17 Feb. 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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!