How to obtain the original matrix of a cumsum()?
5 views (last 30 days)
Show older comments
Philippe Corner
on 21 Mar 2018
Commented: Giacomo Tabarelli
on 29 May 2020
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];
0 Comments
Accepted Answer
John D'Errico
on 21 Mar 2018
Just use diff! Then append the first element.
A = rand(1,10);
B = cumsum(A);
C = [B(1), diff(B)];
3 Comments
Giacomo Tabarelli
on 29 May 2020
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?
More Answers (0)
See Also
Categories
Find more on Logical 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!