Using integral function for a function which is defined with an integral

3 次查看(过去 30 天)
I want to use the integral function in Matlab 2012a to integrate the function
phi = @(x) integral(@(t) exp(-t.^2./2),-inf,x);
but I get an error when the integrate function passes vector-valued x to
integral(@(t) exp(-t.^2./2),-inf,x);
I tried to define a function
function out = innerIntegralMultiple(x)
inner = @(t) exp(-t.^2./2);
if(isscalar(x))
out = integral(inner,-inf,x);
return;
end
out = zeros(length(x),1);
for i=1:length(x)
out = integral(inner,-inf,x(i));
end
end
and define phi as
phi = @(x) innerIntegralMultiple(x)
but I get errors about the number of arguments the function returns when I try this definition.
Is there a way to do what I want?

回答(1 个)

Mike Hosea
Mike Hosea 2012-6-5
>> phi = @(r)arrayfun(@(x)integral(@(t)exp(-t.^2./2),-inf,x),r);
>> phi(-3:3)
ans =
Columns 1 through 5
0.003383692573953 0.057026123992892 0.397689745423351 1.253314137315500 2.108938529207654
Columns 6 through 7
2.449602150637674 2.503244582076109

类别

Help CenterFile Exchange 中查找有关 Numerical Integration and Differentiation 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by