简体   繁体   中英

How would you write this function in python?

in a subject for a class I need to create a plot of various functions like: 𝑛 ∗ 𝑙𝑜𝑔2(𝑛), converting them to something like this: n * np.log2(n)

The following one is giving me some problems: 𝑡 ∗ 𝑛 ∗ 𝑙𝑜𝑔10(𝑛) on 1 <= 𝑡 <= 9

I have to call the function and give (n) as an argument but I don´t know how to represent that one.

I am editing this question because I wasn´t very clear. I have a function where I need to convert text equations to python euquations like stated above:

def plot_funs(xs):

    js0 = [x**2+2 for x in xs]
    js1 = [x + np.log2(x) for x in xs]
    js1_b = [t*x*np.log10(x) for x in xs]
    yjs2 = [3 + np.log2(6*x) + x for x in xs]

Then the function is ploted. If the t is ignored, it would return something like this:

在此处输入图像描述

But the problem is that i don´t know how to plot the t mentioned above.

This exercise is focusing on studying the function growths if that helps.

Thanks for your help.

You can take an input from the user by input() , and construct the t vector as np.arange() , then write the equation and plot using matplotlib.pyplot .

import numpy as np
import matplotlib.pyplot as plt

print('Enter value for n:')
n = int(input())
t = np.arange(1,n+0.01,0.01)
f = t * n * np.log10(n)

plt.plot(t,f)
plt.show()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM