How do I evaluate an integral over a matrix with unique functions in each element?
Show older comments
Hi i'm solving a finite element problem, where i need to evaluate a 2D integral over a function like this.
fun = @(x,y) [f1(x,y) f2(x,y); f3(x,y) f4(x,y)];
It's a matrix with unique functions at each element, but it has the same variables and the same boundaries (a < x < b, c(x) < y < d(x))
I tried quad2D, but it wont work. Is it because quad2d only works with scalar functions? What i tried to do was something like this.
fun = @(x,y) [sin(x).*cos(y) sin(x).*cos(y); sin(x).*cos(y) sin(x).*cos(y)];
f1 = @(x) x;
f2 = @(x) 1-x;
quad2d(fun,0,1,f1,f2);
But it returns
??? Error using ==> quad2d>tensor at 350
Integrand output size does not match the input size.
Error in ==> quad2d at 164
[Qsub,esub] = tensor(thetaL,thetaR,phiB,phiT);
Error in ==> eval_int at 4
quad2d(fun,0,1,f1,f2);
Please help!
Answers (1)
Andrei Bobrov
on 28 Apr 2014
Edited: Andrei Bobrov
on 28 Apr 2014
f0 = strcat('@(x,y)',repmat({'sin(x).*cos(y)'},2,2));
f0 = cellfun(@str2func,f0,'un',0);
out = cellfun(@(z),integral2(z,0,1,@(x)x,@(x)1-x),f0)
Categories
Find more on Numerical Integration and Differentiation in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!