stuck on a simple cumsum prob

조회 수: 1 (최근 30일)
Matlab2010
Matlab2010 2012년 5월 29일
I have a variable x. I make a variable y. I now need to regenerate my variable xNew from y.
Its very close but not exact. Why not? what I have done wrong?
x = cumsum(randn(1000,1));
y = 0.5.*(x(3:end) - x(1:end-2));
xNew = cumsum(y);
plot(x(3:end)); hold all; plot(xNew);

채택된 답변

Oleg Komarov
Oleg Komarov 2012년 5월 29일
y = 0.5.*(x(3:end) - x(1:end-2));
Is linear interpolation between point 1 and 3, then between 2 and 4 and so on.
You cannot recover x from the linearly interpolated y unless you are given x(1) and x(end).
EDIT
Suppose you have 5 points only (for simplicity), then:
y2* = (x3-x1)/2;
y3* = (x4-x2)/2;
y4* = (x5-x3)/2;
I assume you know the series of y, i.e. are numbers, but x is unobserved, then you can see that the system has 5 unknowns (x1,...x5) in three equations. Thus, you can have a unique solution only if you are given x1 and x5.
Now, if you are given the x series for comparison reasons, you can guess x1 and x5 then retrieve the rest of the series and compare the distance between xNew and the original one. In an iterative fashion you can then tweak the guess and comapre again the two series, if the distance has dimished then continue tweaking the guess in the same direction until you reach distance = 0.
EDIT#2 You don't need exactly x1 and x5 but any two xi.
  댓글 수: 2
Matlab2010
Matlab2010 2012년 5월 29일
can you recover x(2:end-1)?
Oleg Komarov
Oleg Komarov 2012년 5월 29일
No. See example above.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Thomas
Thomas 2012년 5월 29일
x = cumsum(randn(1000,1));
%y = (x(2:end) - x(1:end-1));
y=[x(1); (x(2:end) - x(1:end-1))];
xNew = cumsum(y);
plot(x(2:end)); hold all; plot(xNew);
isequal(x,xNew)
  댓글 수: 3
Matlab2010
Matlab2010 2012년 5월 29일
yes. but what about "(x(3:end) - x(1:end-2));"
Thomas
Thomas 2012년 5월 29일
Hmm. then as oleg says you need, x(1) and x(end) for each value to interpolate..

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by