## Componentwise Addition of TemporalData

4

1

I'm a little confused with the TemporalData structure in Mathematica, in the sense that it doesn't seem to behave like a list.

What I'd like to do is plot the sum and difference of a Brownian motion and an OU process, and so far, generating and plotting these individual processes is not a problem:

Z = RandomFunction[WienerProcess[0, 1], {0, 1, 0.01}];

L = RandomFunction[OrnsteinUhlenbeckProcess[0, 1, 1, 0], {0, 1, 0.01}];

ListLinePlot[{Z,L}]


However, plotting their sum with

ListLinePlot[Z+L]


yields an error:

ListLinePlot::lpn: TemporalData[Automatic,{<<1>>}]+TemporalData[Automatic,{<<1>>}]
is not a list of numbers or pairs of numbers.


I've checked out this related post, but am unsure how to interpret it in the context of my particular problem. Is there a simple way to do what I'd like?

That's because it's not a list (well, it is in the broadest sense, but really it's an object). Try ListLinePlot[First[Z["States"] + L["States"]]] e.g. – ciao – 2014-05-09T22:33:17.267

for the sake of completenes, ListPlot[Z + L] works perfectly ok with 11.3 – user42582 – 2018-03-21T10:31:46.540

## Answers

8

As noted in my comment, constructs like TemporalData are not meant to be treated as vanilla lists (see the documentation for details on getting "pieces" of them via their properties).

In your case, you're interested in the addition of the states over time, so, e.g.:

Z = RandomFunction[WienerProcess[0, 1], {0, 1, 0.01}];

L = RandomFunction[OrnsteinUhlenbeckProcess[0, 1, 1, 0], {0, 1, 0.01}];

ListLinePlot[{Z, L}]

ListLinePlot[First[Z["States"] + L["States"]]]


5

With the addition of TimeSeriesThread to Mathematica 10 this becomes trivial.

Z = RandomFunction[WienerProcess[0, 1], {0, 1, 0.01}];
L = RandomFunction[OrnsteinUhlenbeckProcess[0, 1, 1, 0], {0, 1, 0.01}];

TimeSeriesThread[Total, {Z, L}] // ListLinePlot


1

As of v.11.3 (probably with v.11 as well, but that's just a guess as I have no access to that version of Mathematica) something like

ListLinePlot[Z+L]


(where the Z and L are defined as in the question) evaluates as expected; there's no need for accessing the "Values" of the underlying TemporalSeries, operating on them and then plotting.