I suggest calling integral
on a handle for your function as below:
h1 = @(x)myfun(x);
h2 = @(x)myfun(x-2);
h3 = @(x)myfun(x.^2);
integral(h1,a,b);
integral(h2,a,b);
integral(h3,a,b);
This should trick the integral function into thinking that you are just defining myfun
as a function of x
while allowing you to pass whatever expression you want to it. You could also pass additional parameters this way, such as:
h = @(x)myfun(x, params);
integral(h,a,b);
Where params
could be a list of parameters that you use in your definition of myfun
.
I hope that helps.
EDIT: I tested this on a server that I have access to which does have the integral
function and it seemed to work. Hopefully this answers your question.