Problem with quad: how to handle a loop in the integrand function ?
Afficher commentaires plus anciens
I would like to integrate over a function which uses a loop. I simplified the example on purpose. This integrand function is :
function [EU]=toy(d1,M)
test=zeros(size(M,1),size(M,2))
for i=1:size(M,1)
for j=1:size(M,2)
test(i,j)=M(i,j)+d1;
end
end
EU=sum(sum(test);
When I use:
ex=quad(@(d1) toy(d1,M),0.3,0.5)
I get an error message:
??? Subscripted assignment dimension mismatch.
Error in ==> toy at 6
test(i,j)=M(i,j)+d1;
Error in ==> @(d1)toy(d1,M)
Error in ==> quad at 76
y = f(x, varargin{:});
However, for any particular value of d1, the function yields a unique number. When I try alternative functions within the loop, I always get some kind of error. Has this to do with the way quad works ? Is there some solution ?
Thanks a lot in advance for your replies.
Best regards,
Guillaume
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!