using quad2d
22 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi, i am trying to use quad2d and running into the following problem: I've a functions defined , e.g.
f1 = @(x,y) x+y
f2 = @(x,y) x-y
f3 = @(x,y) x
f4 = @(x,y) y
I need to integrate dot([f1 f2], [f3 f4]). if I try quad2d(@(x,y) dot([f1 f2], [f3 f4]),a,b,c,d ) it isn't working. Any suggestions as how fix this? thanks
0 comentarios
Respuesta aceptada
Mike Hosea
el 19 de Dic. de 2011
DOT doesn't work on function handles, and as Walter says, QUAD2D requires that the integrand be able to handle matrix input. You don't need all that reshaping, however:
quad2d(@(x,y)f1(x,y).*f3(x,y)+f2(x,y).*f4(x,y),a,b,c,d)
0 comentarios
Más respuestas (1)
Walter Roberson
el 18 de Dic. de 2011
quad2d(@(x,y) dot([f1(x,y) f2(x,y)], [f3(x,y) f4(x,y)]),a,b,c,d )
2 comentarios
Walter Roberson
el 19 de Dic. de 2011
The quad2d() reference says,
All input functions must be vectorized. The function Z=fun(X,Y) must accept 2-D matrices X and Y of the same size and return a matrix Z of corresponding values
However, when you supply matrix arguments, although each of f1, f2, f3, and f4 would return matrices, [f1(x,y) f2(x,y)] is going to be a 2D array with the pieces concatenated along the second dimension (horzcat), and likewise [f3(x,y) f4(x,y)] would be a 2D array with the pieces concatenated along the second dimension, and dot() applied to a pair of 2D arrays will apply the dot product along the first non-singular dimension (which will be the first dimension in this case), giving you a row vector of results rather than a 2D array.
Alternative code:
quad2d(@(x,y) reshape(f1(x(:),y(:)) .* f3(x(:), y(:)) + f2(x(:),y(:)) .* f4(x(:), y(:)), size(x)) )
Ver también
Categorías
Más información sobre Numerical Integration and Differentiation en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!