Skip to content
Advertisement

How to generate random values for a predefined function?

I have a predefined function, for example this:

JavaScript

How can I generate random values against it so I can plot the results of the function using matplotlib?

Advertisement

Answer

If you want to plot, don’t use random x values but rather a range.

Also you should use numpy.exp that can take a vector as input and your y in the lambda should be x (y is undefined).

This gives us:

JavaScript

output:

enter image description here

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement