Reputation: 115
I have a characteristic function CF(t, param1, param2, ...)
available (here param
s are parameters of some distribution and are considered fixed). I want to use Gil-Pelaez formula to obtain the CDF instead, so I wrote the following:
function [ F ] = CDF( x, param1, param2, ... )
integrand = @(v) imag(exp(-1i.*v.*x) .* CF(t, param1, param2, ...)) ./ v;
F = 0.5 - (1./pi) .* integral(integrand, 0, 100);
end
This works for single value, e.g. CDF(0.1, param1, param2, ...)
gives me desired result. Now I want to plot CDF
against a range of x
, so I did
x = linspace(-1,1,100);
y = CDF(x, param1, param2, ...)
plot(x, y)
and I end up with the errors like these:
Not enough input arguments.
Error in integralCalc/iterateScalarValued (line 314)
fx = FUN(t);
Error in integralCalc/vadapt (line 132)
[q,errbnd] = iterateScalarValued(u,tinterval,pathlen);
Error in integralCalc (line 75)
[q,errbnd] = vadapt(@AtoBInvTransform,interval);
Error in integral (line 88)
Q = integralCalc(fun,a,b,opstruct);
But y = CDF(x, param1, param2, ...)
does work, so the culprit seems to be the exp(-1i.*v.*x)
part of the integrand, as the size of v
and x
does not match. But I am not sure how to fix this.
Upvotes: 0
Views: 58
Reputation: 1797
You have guessed it right that the sizes of v and x don't match which is causing the error. integral
passes vector values to the function handle to speed up computations by calculating function values for multiple points at once.
But in this case you should set the parameter 'ArrayValued'
to true
in the call to integral in the CDF function. This would force integral to pass scalar values of v to the function handle and then CDF would be able to return vector valued y
for vector valued x
Upvotes: 1