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!