簡體   English   中英

如何用2個變量繪制函數並在R中包含因子

[英]How to plot function with 2 variables and involving factorials in R

我找不到解決這個問題的可行方案(我是R的初學者)。

我有一個等式,如下所示

在此輸入圖像描述

其中nK是常數。 ab是變量。

如何在R中生成上述二維圖?

提前致謝。

factorialfunction <-function(a,b, n, K){
K*(b^a)*((2+b)^(n+a))
}


Klist = c(1,5,10,50,100,200)
nlist = c(1,5,10,50,100,200)
#note that the n and K values are recycled, make them whatever you wish, they are constants, 
#while a and b take on any values, here 100 values between zero and one
res <- mapply(factorialfunction,a = seq(.01,1,by=.01),
b=seq(.01,1,by=.01), n = rep(nlist,each = 100), K=rep(Klist, each=100))

#Then you can plot this six times.

#allow six plots on the panel if you want
par(mfrow = c(3,2))
#loop through different plots
for (i in 1:6)
plot(1:100,res[1:100 + (i-1)*100])

注意在這段代碼中我選擇a和b在0和1之間,我不熟悉這個函數,但它看起來像某種類型的Beta。

您可以通過更改klistnlist以及parfor循環參數來生成超過6個圖。

這是你得到的,請注意這個代碼是可自定義的,以生成你想要的n,K,a和b值的圖。 在此輸入圖像描述

暫無
暫無

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

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