Is there an alternative function to diff(X) giving the same number of element as X?
조회 수: 11 (최근 30일)
이전 댓글 표시
hello again,
Following my question here ("How to apply integral on a vector?"), I am looking to find again the value of y'=y, by derivation of z:
y = x^2 ;
z = ∫ y dx ;
y' = dz/dx = d(1/3*x^3)/dx = x^2 = y ;
With the integration using the following method:
a = -20; b = 20; % lower limit a, upper limit b
dx = 0.01; % increment in x array
X = a:dx:b; %array X
Y = X.^2; %array Y
Z = dx*cumtrapz(Y); % evaluates cumulative integral using traezoidal method
I find z correctly.
To find y'=diff(z), diff gives me a vector of one fewer element, which is logical.
But I do need to find the exact vector y=y'. Does anyone know an alternative function to diff(z) that does not need any function creation? Maybe write me the corresponding code that goes with it if it is complicated?
Thank You in advance.
댓글 수: 0
답변 (2개)
Image Analyst
2020년 5월 15일
Usually what people to is to prepend a 0, like this:
differences = [0, diff(z)];
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Performance and Memory에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!