NaN (Not a Number) problem in integration

Hi all. I am trying to calculate this integration, it gives NaN ,instead of pi/2. How can I solve the problem?
mz=zeros(4,1); h=zeros(4); I=eye(4);
f=@(x)(arrayfun(@(x)(exp(-mz'*(1./(h+((sin(x).^2).*I)))*mz)),x));
out = quad(f,0,pi/2)
Thanks

 Réponse acceptée

José-Luis
José-Luis le 19 Sep 2012
Modifié(e) : José-Luis le 19 Sep 2012
No, it should not give you pi/2. The way you have set up your matrices, the expression
h+((sin(x).^2).*I)))*mz
will always be equal to zero. Division by 0 = Inf.

4 commentaires

Serhat
Serhat le 19 Sep 2012
You misunderstood, ((h+((sin(x).^2).*I)).^-1)*mz is my function. So it equals 1/(I matrix) * mz and mz=0, then the function is 0=>exp(0)=1 isn't it?
José-Luis
José-Luis le 19 Sep 2012
Modifié(e) : José-Luis le 19 Sep 2012
I'm afraid it's not. Have you tried to visualize your function? Copy/pasting your code and running:
f(0) = NaN;
f(whatever) = NaN;
and that is because
exp(-mz'*(1./(h+((sin(x).^2).*I)))*mz)
will evaluate to NaN, with mz and I defined as you did. Maybe you have misplaced a parentheses?
Serhat
Serhat le 19 Sep 2012
Now it works, you are right. I put parentheses at wrong places. Thank you very much.
f = @(theta)(arrayfun(@(x)(det(sigmaZ./sin(x).^2+eye(4,4)).^-1)*exp(-1*mZ'*1/(sigmaZ+sin(x).^2.*eye(4))*mZ),theta));
José-Luis
José-Luis le 19 Sep 2012
My pleasure.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Matrices and Arrays 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!

Translated by