Grabbing number from array to calculate the numerical derivative
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Mateusz Brzezinski
il 17 Feb 2020
Commentato: Mateusz Brzezinski
il 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 Commenti
Risposta accettata
James Tursa
il 17 Feb 2020
Modificato: James Tursa
il 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 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Matrix Indexing 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!