Double integration using dblquad not working
1 次查看(过去 30 天)
显示 更早的评论
what is the mistake in this code, I'm getting this error "Error using dblquad>innerintegral (line 76)
Inputs must be floats, namely single or double."
SNRdB = 1;
SNR=10.^(SNRdB./10);
sigma=1./SNR;
sigma_1=(sqrt(3./4)).*sigma;
sigma_2=(sqrt(1./4)).*sigma;
syms mu_x sigma_x s dot_s
f_x=(1./(2*pi*(sigma_x).^2)).*exp(-(s-mu_x).^2./(2.*(sigma_x).^2))
f_s_1=subs(f_x,[mu_x,sigma_x],[dot_s,sigma_1])
f_dot_s=subs(f_x, [mu_x,sigma_x],[0,1]);
Pr=erf(s./(s.*sigma_2))*f_s_1*f_dot_s
Fun=@(x,y)subs(Pr,[s,dot_s],[x,y])
Pr_pos_c = dblquad(@(x,y)Fun(x,y),-inf,inf,0,inf)
0 个评论
回答(1 个)
Steven Lord
2019-6-14
The function you pass into dblquad must return a double or single value. It cannot return a sym object. To compute a double integral using sym objects, call int twice. Alternately if you want to use dblquad (or the integral2 function, which is the recommended replacement for dblquad) convert your symbolic expression into a function handle using matlabFunction or call double on the results of the subs call inside your Fun function.
Fun=@(x,y)double(subs(Pr,[s,dot_s],[x,y]))
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Assumptions 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!