필터 지우기
필터 지우기

Grabbing number from array to calculate the numerical derivative

조회 수: 1 (최근 30일)
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.

채택된 답변

James Tursa
James Tursa 2020년 2월 17일
편집: James Tursa 2020년 2월 17일
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
Mateusz Brzezinski
Mateusz Brzezinski 2020년 2월 18일
Thanks for the answer but It does not work as it should.
is than any option to do it "manually" as second order approximation?
Mateusz Brzezinski
Mateusz Brzezinski 2020년 2월 18일
Forget what I have said.... I had diffrent inputs now they match... Sorry and thanks a lot.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by