numerically integrate multidimensional function along one dimension.

11 views (last 30 days)
sasha on 11 Nov 2014
Edited: Mike Hosea on 13 Nov 2014
I have a function: f(x,y,z). I want to numerically integrate this function along x and be left with a function of only y and z. I can't seem to figure out how to do this. Any help would be appreciated.
Thanks
1 CommentShowHide None
Torsten on 12 Nov 2014
How is f given ? By an explicit equation for f depending on x, y and z ?
Best wishes
Torsten.

Sign in to comment.

Answers (2)

Charles on 11 Nov 2014
Edited: Charles on 12 Nov 2014
Integrate how?
Do you have a function of x,y,z or is time also a variable?
Also, how would this eliminate x? The integral of (x) is (1/2)*(x^2) + x(0) ... not only do you NOT get rid of x, you in fact get a higher order of x.
Are you sure you aren't looking for a partial derivative? Or do you just want to set x = some constant and have the function of f(y,z) along that particular value?
Integrating or taking a derivative will not leave you with the same function.
0 CommentsShowHide -1 older comments

Sign in to comment.

Mike Hosea on 13 Nov 2014
Edited: Mike Hosea on 13 Nov 2014
I will assume here that your function f(x,y,z) is written so that x, y, and z can be any size (vectors, matrices, N-D, whatever) and f(x,y,z) will be computed "element-wise". If this isn't the case, you can use arrayfun to build it up
fnew = @(x,y,z)arrayfun(f,x,y,z);
You should try your function on some array inputs if this is not clear, e.g. evaluate f([1,2,3],[4,5,6],[7,8,9]). The result should match [f(1,4,7),f(2,5,8),f(3,6,9)].
Now define a function of y and z where y and z are assumed to be scalars :
fyz_scalar = @(y,z)integral(@(x)f(x,y*ones(size(x)),z*ones(size(x)),xmin,xmax);
Now "vectorize" the function so that y and z can be arrays of any size (as long as they are the same size).
fyz = @(y,z)arrayfun(fyz_scalar,y,z);
0 CommentsShowHide -1 older comments

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!