# problem integrate function and plotting this function

Hi,
I have three functions (K2, K3, K3),
I would like to plot fp function of p (proportion) for K2 in the same drawing for K3 and K4, however, I have a problem in fp, I don't know where's the problem.

``````K2 <- function(s) {(15/8)*(1-s^2)^2}
K3 <- function(s) {(35/16)*(1-s^2)^3}
K4 <- function(s) {(315/128)*(1-s^2)^4}

fp <- function(p){
(integrate(function(s){s^(-(1/p)+1)}*(K2)^2, 0, 1))\$v-(p/(2*p-1))
}
p=seq(0.1, 0.99, by=0.01)
plot(p,fp,type="l",col="blue", ylim=c(-0.5,0.5), ylab="", lwd = 1)
}
``````

I see 2 problems at first look.

1. \$v appears but seems to be undefined.
2. K2 is a function but not used as one within fp definition, it is treated like a number which it is not, its a function that would need to be passed a parameter on order to be evaluated to a number.

I don't know how I solve this problem. . Please, can you help me?

``````K2 <- function(s) {(15/8)*(1-s^2)^2}

f <- function(p){
g <-(function(s){s^(-(1/p)+1)})*(K2)^2
integrate(g, 0.01, 1)\$v-(p/(2*p-1))
}
p=seq(0.6, 0.99, by=0.01)
plot(p,f,type="l",col="blue", ylab="", lwd = 1)

``````

Thank you

Because you haven't explained your intentions in detail , helping you is a guessing game... but I will guess.

Probably replace this with `(K2(s))^2`

Thank you
I found my problem : () and (K2(s))^2

``````g <-function(s){s^(-(1/p)+1)*(K2(s))^2}
``````