Is there an alternative function to diff(X) giving the same number of element as X?
13 views (last 30 days)
Show older comments
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 Comments
Answers (2)
Image Analyst
on 15 May 2020
Usually what people to is to prepend a 0, like this:
differences = [0, diff(z)];
0 Comments
See Also
Categories
Find more on Performance and Memory in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!