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
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.
Deema42
Deema42 2019-4-1
@Torsten Why is that? I am trying to make a double summation here by two for loops.

请先登录,再进行评论。

采纳的回答

darova
darova 2019-3-30
F1 = @(z) 0; F2 = @(z) 0;
F1 = @(z) F1(z) + F1_in(z);
F2 = @(z) F2(z) + F1_in(z);

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

产品


版本

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by