Error in numerical integration that I do not understand
1 次查看(过去 30 天)
显示 更早的评论
I am trying to integrate a function numerically and I get an error that I do not understand. The error is :
Undefined function or variable 'z'.
How can "z" be undefined if this is the parameter of the function I am trying to numerically integrate?!
clear ; close all;
k1 = 1; mu1 = 1;
k2 = 1; mu2 = 1;
lamdap = 1; lamdae = 10;
ro = 10.^(5./10);
cth = 1; alpha = 2.^(2.*cth);
F1=0;F2=0;
for q=0:5
for w=0:5
F1_in=@(z) (((2.*(((mu2.*(1 + k2)).^(mu1 - mu2 + q - w)).*mu1.*(1 + k1).^((mu1 + 1)./2).* mu2.*(1 + k2).^((mu2 + 1)./ 2).*((2.*mu1.*sqrt(k1.*(1 + k1))).^(2.*q + mu1 - 1)).*((2.*mu2.*sqrt(k2.*(1 + k2))).^(2.*w + mu2 - 1))))./((k1.^((mu1 - 1)./2)).*(k2.^((mu2 - 1)./2)).*exp(k1.*mu1).*exp(k2.*mu2).* gamma(q + mu1).*gamma(w + mu2).*factorial(q).*factorial(w).*2.^(2.*q + mu1 - 1).*2.^(2.*w + mu2 - 1)))).*((lamdap.* lamdae)./((-lamdap.*alpha.*ro) + (lamdae.*(alpha - 1)))) .*(1./(2.*ro)).*(1./(ro.^(mu1 + q - 1))).*(lamdap./(alpha - 1)).^(-mu1 - q - 1).*z.^(-mu1 - q - 1).* MeijerG({[mu1 - mu2 + q - w + 1, 1], []}, {[1 + mu1 + q], []}, (z.* ro.*lamdap./(mu1.*mu2.*(1 + k1).*(1 + k2).*(alpha - 1))));
F1=F1+F1_in(z);
end
end
for q=0:5
for w=0:5
F2_in=@(z) (((2.*(((mu2.*(1 + k2)).^(mu1 - mu2 + q - w)).*mu1.*(1 + k1).^((mu1 + 1)./2).* mu2.*(1 + k2).^((mu2 + 1)./ 2).*((2.*mu1.*sqrt(k1.*(1 + k1))).^(2.*q + mu1 - 1)).*((2.*mu2.*sqrt(k2.*(1 + k2))).^(2.*w + mu2 - 1))))./((k1.^((mu1 - 1)./2)).*(k2.^((mu2 - 1)./2)).*exp(k1.*mu1).*exp(k2.*mu2).* gamma(q + mu1).*gamma(w + mu2).*factorial(q).*factorial(w).*2.^(2.*q + mu1 - 1).*2.^(2.*w + mu2 - 1)))).*((lamdap.* lamdae)./((-lamdap.*alpha.*ro) + (lamdae.*(alpha - 1)))) .*(1./(2.*ro)).*(1./(ro.^(mu1 + q - 1))).*(lamdae./(alpha .*ro)).^(-mu1 - q - 1).*z.^(-mu1 - q - 1).*MeijerG({[mu1 - mu2 + q - w + 1, 1], []}, {[1 + mu1 + q], []}, (z.* lamdae./(mu1.*mu2.*(1 + k1).*(1 + k2).*(alpha))));
F2=F2+F2_in(z);
end
end
P = @(z)( F1(z) - F2(z));
result = integral(P,1,100);
semilogy(ro,result,'LineWidth',1.5)
2 个评论
Torsten
2019-4-1
Note that the loops over q and w are superfluos ; F1_in and F2_in will take only one combination of w and q in the integration, namely q=w=5.
采纳的回答
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!