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!