MATLAB Answers

How to obtain the original matrix of a cumsum()?

1 ビュー (過去 30 日間)
Philippe Corner
Philippe Corner 2018 年 3 月 21 日
コメント済み: Giacomo Tabarelli 2020 年 5 月 29 日
if we have a matrix B = cumsum(A);
B=[0.102493854430154 0.107645445153016 0.109982543018989 0.111250846129182 0.112023941002529
0.252983718693220 0.267537140617764 0.274291923474296 0.277936513591507 0.280166731981901
0.446994905411664 0.475357155580891 0.488884534539884 0.496152338879191 0.500676903345327
0.681174961701521 0.727902668424241 0.750721436460152 0.763062453240230 0.770697210445687
0.954490719298870 1.02481028893085 1.05975275214650 1.07879511204532 1.09055541700809];
how to obtain the "cumdiff" of the matrix B and obtain A.
Answer is:
A=[0.102493854430154,0.107645445153016,0.109982543018989,0.111250846129182,0.112023941002529;0.150489864263066,0.159891695464748,0.164309380455307,0.166685667462325,0.168142790979372;0.194011186718444,0.207820014963127,0.214592611065588,0.218215825287684,0.220510171363426;0.234180056289857,0.252545512843350,0.261836901920268,0.266910114361039,0.270020307100360;0.273315757597349,0.296907620506609,0.309031315686344,0.315732658805087,0.319858206562400];

採用された回答

John D'Errico
John D'Errico 2018 年 3 月 21 日
Just use diff! Then append the first element.
A = rand(1,10);
B = cumsum(A);
C = [B(1), diff(B)];
  3 件のコメント
Giacomo Tabarelli
Giacomo Tabarelli 2020 年 5 月 29 日
Ok I know about floating point numbers. My question is why there is such a difference? Is there a way to avoid this errors? I need this to compute SDE convergence errors. I found problems in the order of convergence and investigating I found this. Any suggestion?

サインインしてコメントする。

その他の回答 (0 件)

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by