簡體   English   中英

你會如何在 python 中編寫這個函數?

[英]How would you write this function in python?

在一個課程的主題中,我需要創建一個包含各種函數的圖,例如:𝑛 * 𝑙𝑜𝑔2(𝑛),將它們轉換成這樣的東西: n * np.log2(n)

以下是給我一些問題:𝑡 ∗ 𝑛 ∗ 𝑙𝑜𝑔10(𝑛) on 1 <= 𝑡 <= 9

我必須調用該函數並將 (n) 作為參數,但我不知道如何表示該參數。

我正在編輯這個問題,因為我不是很清楚。 我有一個函數,我需要將文本方程轉換為 python euquations,如上所述:

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]

然后繪制函數。 如果 t 被忽略,它將返回如下內容:

在此處輸入圖像描述

但問題是我不知道如何繪制上面提到的 t 。

如果有幫助,這個練習的重點是研究功能增長。

謝謝你的幫助。

您可以通過input()從用戶那里獲取輸入,並將t向量構造為np.arange() ,然后使用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()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM