Double integration using dblquad not working

조회 수: 4 (최근 30일)
Diana
Diana 2019년 6월 14일
댓글: Diana 2019년 6월 14일
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)

답변 (1개)

Steven Lord
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]))
  댓글 수: 3
Diana
Diana 2019년 6월 14일
I tried to replace Fun=@(x,y)subs(Pr,[s,dot_s],[x,y]) with Fun=@(x,y)double(subs(Pr,[s,dot_s],[x,y])) and I got this eror
Error using sym/subs>normalize (line 205)
The lengths of the second and third arguments are inconsistent.
Diana
Diana 2019년 6월 14일
Note also that if I used =int(int(Pr,[-inf inf]),[0 inf]) instead of Pr_pos_c = dblquad(@(x,y)Fun(x,y),-inf,inf,0,inf), I don't get an error but I get this as an answer
int(int((1125899906842624*exp(-s^2/2)*exp(-(2535301200456458802993406410752*(dot_s - s)^2)/2399500369346179911436460901961)*(erf((2251799813685248*s)/1788668170957069)/2 + 1/2))/(1549032074989469*pi), s, -Inf, Inf), dot_s, 0, Inf)
but I don't get a finite number

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Calculus에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by