string_is_hard
string_is_hard

Reputation: 29

Matlab: how to integrate over subset of input variables of a function while fixing the value of the other variables?

suppose I want to integrate a function of the form output=myfunc(x,y,var1,var2,...,varN) with respect to just the x and y variable, over the region of x for x0 to x1, and y from fy0(x) to fy1(x), where fy0() and fy1() are two function of x. The other variables of myfunc() - var1, var2, ..., varN will take some fixed value each time I do the 2d integral.

btw: myfunc() is rather long and can't be written as an anonymous function with @.

how can I do it? many thanks!

Upvotes: 0

Views: 62

Answers (1)

Daniel
Daniel

Reputation: 36710

First of all, fix all the constants to get a 2-parameter function:

var1=3
var2=pi
myfunc2=@(x,y)myfunc(x,y,var1,var2)

This way myfunc2 is a anonymous function which calls myfunc with the given x and y and the defined values for var1 amd var2. Keep in mind that myfunc2 copies the variables to it's own scope. If you modify var1 and var2 after creating the anonymous function it won't modify myfunc2.

Now you can use integral2. For ymin and ymax function handles are accepted.

Upvotes: 1

Related Questions