# trapezoidal rule

Hello,

I need to integrate this equation (((2^(1/a))ab*(hypergeo(-1/a,(-1+a)/a,2-(1/a),1/2)+((1/(1-p))^(1/a))*(-1+p)*hypergeo(-1/a,(-1+a)/a,2-(1/a),(1-p)/2)))/((-1+a)mp)).

So, I tried to integrate using trapezoidal rule in R using 'pracma' package . but I keep getting an error ''Error in trapz(x, y) :
Arguments 'x', 'y' must be vectors of the same length.'' I have no idea on how to solve this. Please help me.

Here, the 'a','b','m' are the constants (which I already computed earlier) and 'p' is the variable that I want to integrate with respect to. 'p' should be any number between 0 to 1. For this integral, the lower bound is 0, and the upper bound is 1.

``````  n<-1000
x<-seq(0,1,len=n)
fn<-function(a,b,p,m){
equ<-(((2^(1/a))*a*b*(hypergeo(-1/a,(-1+a)/a,2-(1/a),1/2)+((1/(1-p))^(1/a))*(-1+p)*hypergeo(-1/a,(-1+a)/a,2-(1/a),(1-p)/2)))/((-1+a)*m*p))
return(equ)
}
y<-fn(a=2.686628, b=36695.74,p=0.4,m=69556.6)
trapz(x,y)

``````

Hi, have you tried this?

``````y<-fn(a=2.686628, b=36695.74,p=x,m=69556.6)
``````

That way x and y will have the same length. Also p is the variable you are trying to integrate with respect to, so if you say `p=0.4`, you are just getting a single value of f(a,b,p,m).

Hi, yes you're right. TQ TQ TQ This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.