# How do I define and plot a function involving random variable? [closed]

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

## closed as unclear what you're asking by Pillsy, Sektor, JimB, N.J.Evans, gwrNov 9 '18 at 22:57

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

• Take a look at UniformDistribution and TransformedDistribution. I think it may help you. – Gustavo Delfino Nov 8 '18 at 18:29
• 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. – mikado Nov 8 '18 at 19:31

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


Between 0 and 500:

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


SeedRandom[0]

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

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


• Thank you very much guys!! – strange world Nov 8 '18 at 20:17