Clear Filters
Clear Filters

Error in numerical integration that I do not understand

1 view (last 30 days)
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 Comments
Torsten
Torsten on 1 Apr 2019
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 on 1 Apr 2019
@Torsten Why is that? I am trying to make a double summation here by two for loops.

Sign in to comment.

Accepted Answer

darova
darova on 30 Mar 2019
F1 = @(z) 0; F2 = @(z) 0;
F1 = @(z) F1(z) + F1_in(z);
F2 = @(z) F2(z) + F1_in(z);

More Answers (0)

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Products


Release

R2017a

Community Treasure Hunt

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

Start Hunting!