4
$\begingroup$

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?

$\endgroup$
  • $\begingroup$ 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. $\endgroup$ – ciao May 9 '14 at 22:33
  • $\begingroup$ for the sake of completenes, ListPlot[Z + L] works perfectly ok with 11.3 $\endgroup$ – user42582 Mar 21 '18 at 10:31
8
$\begingroup$

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"]]]

enter image description here

enter image description here

$\endgroup$
5
$\begingroup$

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

enter image description here

$\endgroup$
1
$\begingroup$

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.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.