Plotting a Function With Noise

I always wondered how such pictures are made:

enter image description here

I am working with the R programming language. I would like to plot a parabola with "random noise" added to the parabola. I tried something like this:

x = 1:100
y = x^2
z = y + rnorm(1, 100,100)

plot(x,z)

enter image description here

But this is still producing a parabola without "noise".

Can someone please show me how I can add "noise" to a parabola (or any function) in R?

Thanks!

>Solution :

In this case you need to generate 100 random points or will be adding the same amount of noise to each point (thus no noise). z = y + rnorm(100, 100,100)

x = 1:100
y = x^2
z = y + rnorm(length(y), 100,100)

plot(x,z)

Leave a Reply