matlab 定积分数值解 显示NaN 重点就在最后三行 求大神帮我解决一下 我的定积分问题
close all
clear all
format long
P=10;
det=0.1;
hij=0.4;
syms vij;
syms x;
syms fij;
sample=raylrnd(1,P,1);
r=(vij-sample).^2;
r2=(vij-sample);
syms temp sum1 sum2 gkl A;
% r1=(-1)/2*(det^2+hij^2)*sum(r);
sum1=0;
sum2=0;
for i=1:P
temp=exp((-1)/2*(det^2+hij^2)*r(i));
sum1=sum1+temp;
end
rf=1/(P*sqrt(2*pi*(det^2+hij^2)));
fij=rf*sum1;
temp=0;
for i=1:P
temp=exp((-1)/2*(det^2+hij^2)*r(i))*r2(i)/(det^2+hij^2);
sum2=sum2+temp;
end
gkl=rf*sum2;
A=gkl^2/fij;
rjy=simplify(A);
fun=inline(rjy,'vij');
IL=quadl(fun,-inf,inf)
IL结果是NaN
咋整?
我是不是最后定积分那块求得不对? 展开
%%%% 由图可看出函数fun在-inf和inf处趋于0,因此可以把积分上下限设为-20, 20
------------------------------------------------------------
clear;clc
P=10;
det=0.1;
hij=0.4;
syms vij x
sample=raylrnd(1,P,1);
r=(vij-sample).^2;
r2=(vij-sample);
sum1=0;sum2=0;
for i=1:P
temp=exp((-1)/2*(det^2+hij^2)*r(i));
sum1=sum1+temp;
end
rf=1/(P*sqrt(2*pi*(det^2+hij^2)));
fij=rf*sum1;
temp=0;
for i=1:P
temp=exp((-1)/2*(det^2+hij^2)*r(i))*r2(i)/(det^2+hij^2);
sum2=sum2+temp;
end
gkl=rf*sum2;
A=gkl^2/fij;
rjy=simplify(A);
fun=inline(rjy,'vij');
ezplot(fun,[-20 20]) % 由图可看出函数fun在-inf和inf处趋于0
IL=quadl(fun,-20,20)
%%%%%%%%运行结果:
>> IL=quadl(fun,-20,20)
IL =
1.119219216991000e+003
>>