PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, October 7, 2022

[FIXED] How to generate random values for a predefined function?

 October 07, 2022     matplotlib, numpy, python, scipy, statistics     No comments   

Issue

I have a predefined function, for example this:

my_func = lambda x: (9 * math.exp((-0.5 * y) / 60))/1000

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


Solution

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:

import numpy as np
import matplotlib.pyplot as plt

my_func = lambda x: (9 * np.exp((-0.5 * x) / 60))/1000

xs = np.arange(-1000,10)

plt.plot(xs, my_func(xs))

output:

enter image description here



Answered By - mozway
Answer Checked By - Senaida (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing