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

조회 수: 4 (최근 30일)
raoulcousins
raoulcousins 2012년 6월 5일
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