Filter löschen
Filter löschen

Is there an alternative function to diff(X) giving the same number of element as X?

11 Ansichten (letzte 30 Tage)
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.

Antworten (2)

Image Analyst
Image Analyst am 15 Mai 2020
Usually what people to is to prepend a 0, like this:
differences = [0, diff(z)];

Walter Roberson
Walter Roberson am 15 Mai 2020
gradient().

Kategorien

Mehr zu Performance and Memory finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by