2
$\begingroup$

I am struggling to define and and plot the following function:

$\qquad \sin(x) + 0.15\,u$

where u is a uniform random variable in the range [-1, 1].

How can I define such a function and then plot it for $x$ over the range [0, 500]?

$\endgroup$
  • 1
    $\begingroup$ Take a look at UniformDistribution and TransformedDistribution. I think it may help you. $\endgroup$ – Gustavo Delfino Nov 8 '18 at 18:29
  • 2
    $\begingroup$ This is not really a well-defined problem. You are wanting to plot a realisation of a random process. Do you have one value of u for all values of x? Or do you have an independent value of u for every real value of x? If the latter, when you plot it (at any resolution) you will only see a vertical bar around the curve. $\endgroup$ – mikado Nov 8 '18 at 19:31
4
$\begingroup$

You can define a function with randomness almost exactly like defining a regular (deterministic) function:

f[x_] := Sin[x] + 0.15*RandomVariate[UniformDistribution[{-1, 1}]];
Plot[f[x], {x, 0, 10}]

enter image description here

Between 0 and 500:

Plot[f[x], {x, 0, 500}]

enter image description here

| improve this answer | |
$\endgroup$
2
$\begingroup$
SeedRandom[0]

data = Table[{x, 
    Sin[x] + 0.15*RandomVariate[UniformDistribution[{-1, 1}]]}, {x, 0,
     500, 0.25}];

ListLinePlot[data, Frame -> True, ImageSize -> Large]

enter image description here

| improve this answer | |
$\endgroup$
  • $\begingroup$ Thank you very much guys!! $\endgroup$ – strange world Nov 8 '18 at 20:17

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