Integrating a function including mvnpdf. Error: Input function must return 'double' or 'single' values. Found 'sym'.

1 回表示 (過去 30 日間)
ASKH
ASKH 2019 年 10 月 29 日
コメント済み: ASKH 2019 年 10 月 30 日
Hi,
I want to integrate the function fun below. It consists of a variable X multiplied by the multi-variable pdf of X and the correlated variable Y.
I get the error message "Input function must return 'double' or 'single' values. Found 'sym'." (see below).
fun = @(Y,X) X .* mvnpdf([X Y],mu,sigma); %where mu is 1-by-2 and sigma is 2-by-2
u = @(Y) log(C) + Y; %where C is a scalar constant
test = integral2(fun,-inf,inf,-inf,u);
Error using integral2Calc>integral2t/tensor (line 231)
Input function must return 'double' or 'single' values. Found 'sym'.
When I let X and Y be independent, so replace mvnpdf(....) by the product of their marginal pdfs, it works (then I redefine the variables and use lognpdf). I believe the error comes from the fact that my function fun gives symbolic output, even when supplied with arguments:
fun(1,2)
ans =
2*exp(- (5*conj(X) - conj(Y))^2/48 - conj(Y)^2/2 - 261924464376925987/144115188075855872)
But why is this? Is this the reason I cannot integrate my function? Grateful for help! Thanks!

回答 (1 件)

Catalytic
Catalytic 2019 年 10 月 29 日
Yes, that is the reason. Maybe you have made sigma or mu symbolic variables?
  1 件のコメント
ASKH
ASKH 2019 年 10 月 30 日
Hi,
Thanks for your response! No, sigma and mu are numbers (doubles):
mu =
0 0
sigma =
1.0000 0.2000
0.2000 1.0000
Do you have any idea for why my function would not give numbers as output? Perhaps I need to restrict the (X,Y) to be only real? Why are their complex conjugates showing up? Or does the mvnpdf not have a closed form...?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeArduino Hardware についてさらに検索

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by