How can I calculate integral?

Hi all, I am new to matlab. I am using matlab R2012. I am trying to calculate this integral:
sigmaZ=rand(4,4); syms theta; Ps = 1/pi*(int(1./(det( (sigmaZ./(sin(theta)).^2 + eye(4)))),theta,0,pi/2));
It gives this error message:
?? The following error occurred converting from sym to double: Error using ==> mupadmex Error in MuPAD command: DOUBLE cannot convert the input expression into a double array.
If the input expression contains a symbolic variable, use the VPA function instead.
What is the problem here? Can you help me?
Thanks in advance!

1 Comment

That's strange, I don't get that error. I do get this warning:
Warning: Explicit integral could not be found.
Sorry, no idea why this is happening.

Sign in to comment.

 Accepted Answer

Andrei Bobrov
Andrei Bobrov on 18 Sep 2012
Edited: Andrei Bobrov on 18 Sep 2012
please try this is code:
sigmaZ=rand(4,4);
f = @(theta)1./(arrayfun(@(x)det(sigmaZ/sin(x).^2 + eye(4)),theta));
out = quad(f,0,pi/2);

4 Comments

Thanks, it works. But I didn't understand how it works? Why did you put arrayfun and x-y instead of theta?
Sorry! My typo, corrected.
Function f need to work with a variable - an array that requires algorithm by function quad .
Other form function f , as m-file
function out = f_m_file(theta,sigmaZ)
out = zeros(size(theta));
e1 = eye(size(sigmaZ));
for jj = 1:numel(out)
out(jj) = 1/det(sigmaZ/sin(theta(jj)).^2 + e1);
end
end
Using function f_m_file:
sigmaZ=rand(4,4);
out = quad(@(x)f_m_file(x,sigmaZ),0,pi/2);
Hi again. I have one more question.Now my code is
f = @(theta)(arrayfun(@(x,y)(det(sigmaZ/sin(x).^2 + eye(4)))^-1,theta)); out = quad(f,0,pi/2); I want to add the expression "exp((sin(x)^2.*eye(4))^-1)" to my code.
But when I type f like this
f = @(theta)(arrayfun(@(x,y)((det(sigmaZ/sin(x).^2 + eye(4) ))^-1) *exp(((sin(x).^2).*eye(4))^-1),theta)); out = quad(f,0,pi/2);
It gives an error again. How can I fix it?
Error using arrayfun Non-scalar in Uniform output, at index 1, output 1. Set 'UniformOutput' to false. Error in @(theta)(arrayfun(@(x,y)((det(sigmaZ/sin(x).^2+I))^-1)*exp(((sin(x).^2).*eye(4))^-1),theta)) Error in quad (line 72) y = f(x, varargin{:});
Error in Union_bound_rayleigh (line 104) out = quad(f,0,pi/2);
Thanks
It gives me no solution.
f = @(theta)1./(arrayfun(@(x)det(((sigmaZ/sin(x).^2 + eye(4)).^-1)*exp((sin(x).^2*eye(4)).^-1)),theta));
out = quad(f,0,pi/2);

Sign in to comment.

More Answers (1)

Javier
Javier on 18 Sep 2012
Hello Serhat
I dont understand well the integral expression and limits of integration. To solve numerically integrals in MatlabR 2012a (or previous version).
Create a function with the integral expression.
f=@(x)(x.^2)
Next, use qaudl function (in the command window type: doc quadl)
Value=quadl(f,0,1) % 0 and 1 are the limits of integration of f
Hope it helps. Best regards and welcome to Matlab world.
javier

Community Treasure Hunt

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

Start Hunting!