Warning: Non-finite result. The integration was unsuccessful. Singularity likely. > In integral2Calc>integral2t (line 131)

Hi
i run the function
[Is]=currentMoM()
f = 300000000
N = 39
ra = 1
k0 = 6.2832
Z0 = 376.9911
lambda = 1
reason_for_failure = NaN + NaNi
Warning: Non-finite result. The integration was unsuccessful. Singularity likely.
Unrecognized function or variable 'Efieldin'.

Error in solution>@(x)triangle_basisn(x,index_i).*(4./(Z0.*k0)).*Efieldin(x) (line 36)
fun=@(x)triangle_basisn(x,index_i).*(4./(Z0.*k0)).*Efieldin(x);

Error in integralCalc>iterateScalarValued (line 334)
fx = FUN(t);

Error in integralCalc>vadapt (line 148)
[q,errbnd] = iterateScalarValued(u,tinterval,pathlen, ...

Error in integralCalc (line 77)
[q,errbnd] = vadapt(vfunAB,interval, ...

Error in integral (line 87)
Q = integralCalc(fun,a,b,opstruct);

Error in solution>currentMoM (line 37)
gm(index_i) =integral(fun,Phi0(index_i),Phi0(index_i)+2*pi./(N-1));
function [Is]=currentMoM()
%UNTITLED2 Summary of this function goes here
% Detailed explanation goes here
[f,N,ra,k0,Z0,lambda] = parameter()
gamma_const=1.781;
Phi0=zeros(N);
e=exp(1);
dftm=2.*pi./(N-1);
for jj = 1:N+1
Phi0(jj)=(jj-1).*dftm;
end
% delta_c(i) = sqrt((pos(i,1) - pos(i+1,1))^2 + (pos(i,2) - pos(i+1,2))^2);
lmn = zeros(N);
%zmn = zeros(N);
gm = zeros(1,N);
zmn = zeros(N);
%vim = zeros(1,N);
%vsn = zeros(1,N);
coeif=(Z0.*k0./4).*ra.*dftm;
coeifn=(Z0./2).*sin(k0.*ra.*dftm./2);
for index_i = 1:N
for index_j = 1:N
if index_i == index_j
fun = @(x,y)triangle_basisn(x,index_i).*triangle_basisn(y,index_j).*ra.*(1-j.*(2/pi).*log(gamma_const.*k0.*ra*sqrt(2-2*cos(x-y))./2));
reason_for_failure = fun(Phi0(index_i),Phi0(index_j))
lmn(index_i,index_j) =integral2(fun, Phi0(index_i),Phi0(index_i)+2*pi./(N-1),Phi0(index_j),Phi0(index_j)+2*pi./(N-1));
else
fun = @(x,y)triangle_basisn(x,index_i).*triangle_basisn(y,index_j).*ra.^2.*besselh(0,2,k0.*ra*sqrt(2-2*cos(x-y)));
lmn(index_i,index_j) =integral2(fun,Phi0(index_i),Phi0(index_i)+2*pi./(N-1),Phi0(index_j),Phi0(index_j)+2*pi./(N-1));
zmn(index_i,index_j) = lmn(index_i,index_j);
fun=@(x)triangle_basisn(x,index_i).*(4./(Z0.*k0)).*Efieldin(x);
gm(index_i) =integral(fun,Phi0(index_i),Phi0(index_i)+2*pi./(N-1));
end
%vim(index_i) = delta_c(index_i) * exp(j*k0*(xm(index_i)*cos(phi_i)+ym(index_i)*sin(phi_i)));
%vsn(index_i) = delta_c(index_i) * exp(j*k0*(xm(index_i)*cos(phi_s)+ym(index_i)*sin(phi_s)));
end
W = linsolve(zmn,gm');
for ii=1:N
Is(ii)=W(ii);
end
y= Is
end
end
i use the integral2 and i recieve the message Warning: Non-finite result. The integration was unsuccessful. Singularity likely.
> In integral2Calc>integral2t (line 131)
what happen?
also i use the following function
function z=triangle_basisn(phi,kk)
[f,N,ra,k0,Z0,lambda] = parameter();
dftm=2.*pi./(N-1);
for jj = 1:N+1
Phi0(jj)=(jj-1).*dftm;
end
Phin=Phi0;
if kk==1
z=phi./dftm;
elseif ( phi >= Phin(kk-1) ) & ( phi <=Phin(kk));
z=(phi-Phin(kk-1))./dftm;
elseif (phi >= Phin(kk) ) & (phi <=Phin(kk+1));
z=(Phin(kk+1)-phi)./dftm;
end
end
function [f,N,ra,k0,Z0,lambda] = parameter()
%UNTITLED Summary of this function goes here
c0=3e8;
Z0=120.*pi;
ra=1;
N=39;
f=300e6;
lambda=c0./f;
k0=2*pi./lambda;
end
tnak you

Antworten (1)

fun(Phi0(1),Phi0(1))
gives
NaN + 1i*NaN

11 Kommentare

Phi(jj)=(jj-1)*2*π/)Ν-1) is finite
Your function "fun", evaluated at (Phi0(1),Phi0(1)) = (0,0), gives NaN + 1i*NaN. This causes the integration to fail (see the edited code above).
IF i change the limits of integration
lmn(index_i,index_j) =integral2(fun,-pi./(N-1),pi./(N-1),-pi./(N-1),pi./(N-1));
i receive the message Output argument "z" (and possibly others) not assigned a value in the executionwith "triangle_basisn" function.
The point (0,0) is still within the box of integration - thus the problem remains.
And since your if-statement in "triangle_basisn" only handles non-negative values for phi, a value for z is not assigned for an integrational box that contains negative numbers.
if kk==1
z=phi./dftm;
elseif ( phi >= Phin(kk-1) ) & ( phi <=Phin(kk));
z=(phi-Phin(kk-1))./dftm;
elseif (phi >= Phin(kk) ) & (phi <=Phin(kk+1));
z=(Phin(kk+1)-phi)./dftm;
end
If none of the if or elseif conditions are met, then z is not assigned to.
If you treat z as piecewise constant on intervals for Phin as you do in "triangle_basisn", you shouldn't use "integral2".
"integral2" is meant to be used for functions that depend continuously on the independent variable.
In your case, using "trapz" twice is the better choice (after having healed the NaN problem at (0,0)).
Take a look at the example
"Multiple Numerical Integrations"
under
HIi thank !
i m treying trapz bot i recieve the error
Incorrect number or types of inputs or outputs for function permute.
Error in trapz (line 38)
y = permute(y,perm);
Error in currentMoM_NEW (line 41)
lmn(index_i,index_j) =trapz(y,trapz(x,funb,2))
function [Is]=currentMoM()
%UNTITLED2 Summary of this function goes here
% Detailed explanation goes here
[f,N,ra,k0,Z0,lambda] = parameter()
gamma_const=1.781;
Phi0=zeros(N);
e=exp(1);
dftm=2.*pi./(N-1);
for jj = 1:N+1
Phi0(jj)=(jj-1).*dftm;
end
% delta_c(i) = sqrt((pos(i,1) - pos(i+1,1))^2 + (pos(i,2) - pos(i+1,2))^2);
lmn = zeros(N);
%zmn = zeros(N);
gm = zeros(1,N);
zmn = zeros(N);
%vim = zeros(1,N);
%vsn = zeros(1,N);
coeif=(Z0.*k0./4).*ra.*dftm;
coeifn=(Z0./2).*sin(k0.*ra.*dftm./2);
for index_i = 1:N
for index_j = 1:N
if index_i == index_j
x=-pi/2:pi/2
y=-pi/2:pi/2
[X,Y] = meshgrid(x,y);
funa =triangle_basisn(X,index_i).*triangle_basisn(Y,index_j).*ra.*(1-j.*(2/pi).*log(gamma_const.*k0.*ra*sqrt(2-2*cos(X-Y))./2));
lmn(index_i,index_j) =trapz(y,trapz(x,funa,2));
zmn(index_i,index_j) = lmn(index_i,index_j);
else
x=-pi/2:pi/2
y=-pi/2:pi/2
[X,Y] = meshgrid(x,y);
funb = @(x,y)triangle_basisn(X,index_i).*triangle_basisn(Y,index_j).*ra.*besselh(0,2,k0.*ra.*sqrt(2-2.*cos(X-Y)));
lmn(index_i,index_j) =trapz(y,trapz(x,funb,2))
func=@(x)triangle_basisn(x,index_i).*(4./(Z0.*k0)).*Efieldin(x);
gm(index_i) =integral(func,Phi0(index_i),Phi0(index_i)+2*pi./(N-1));
end
zmn(index_i,index_j) = lmn(index_i,index_j);
%vim(index_i) = delta_c(index_i) * exp(j*k0*(xm(index_i)*cos(phi_i)+ym(index_i)*sin(phi_i)));
%vsn(index_i) = delta_c(index_i) * exp(j*k0*(xm(index_i)*cos(phi_s)+ym(index_i)*sin(phi_s)));
end
W = linsolve(zmn,gm');
for ii=1:N
Is(ii)=W(ii);
end
y= Is
end
sorrry i receive the same message
Output argument "z" (and possibly others) not assigned a value in the execution with "triangle_basisn"
function.
Error in currentMoM_NEW (line 40)
funb = triangle_basisn(X,index_i).*triangle_basisn(Y,index_j).*ra.*besselh(0,2,k0.*ra.*sqrt(2-2.*cos(X-Y)));
function [Is]=currentMoM()
%UNTITLED2 Summary of this function goes here
% Detailed explanation goes here
[f,N,ra,k0,Z0,lambda] = parameter()
gamma_const=1.781;
Phi0=zeros(N);
e=exp(1);
dftm=2.*pi./(N-1);
for jj = 1:N+1
Phi0(jj)=(jj-1).*dftm;
end
% delta_c(i) = sqrt((pos(i,1) - pos(i+1,1))^2 + (pos(i,2) - pos(i+1,2))^2);
lmn = zeros(N);
%zmn = zeros(N);
gm = zeros(1,N);
zmn = zeros(N);
%vim = zeros(1,N);
%vsn = zeros(1,N);
coeif=(Z0.*k0./4).*ra.*dftm;
coeifn=(Z0./2).*sin(k0.*ra.*dftm./2);
for index_i = 1:N
for index_j = 1:N
if index_i == index_j
x=-pi/2:pi/2
y=-pi/2:pi/2
[X,Y] = meshgrid(x,y);
funa =triangle_basisn(X,index_i).*triangle_basisn(Y,index_j).*ra.*(1-j.*(2/pi).*log(gamma_const.*k0.*ra*sqrt(2-2*cos(X-Y))./2));
lmn(index_i,index_j) =trapz(y,trapz(x,funa,2));
zmn(index_i,index_j) = lmn(index_i,index_j);
else
x=-pi/2:pi/2
y=-pi/2:pi/2
[X,Y] = meshgrid(x,y);
funb =triangle_basisn(X,index_i).*triangle_basisn(Y,index_j).*ra.*besselh(0,2,k0.*ra.*sqrt(2-2.*cos(X-Y)));
lmn(index_i,index_j) =trapz(y,trapz(x,funb,2))
func=@(x)triangle_basisn(x,index_i).*(4./(Z0.*k0)).*Efieldin(x);
gm(index_i) =integral(func,Phi0(index_i),Phi0(index_i)+2*pi./(N-1));
end
zmn(index_i,index_j) = lmn(index_i,index_j);
%vim(index_i) = delta_c(index_i) * exp(j*k0*(xm(index_i)*cos(phi_i)+ym(index_i)*sin(phi_i)));
%vsn(index_i) = delta_c(index_i) * exp(j*k0*(xm(index_i)*cos(phi_s)+ym(index_i)*sin(phi_s)));
end
W = linsolve(zmn,gm');
for ii=1:N
Is(ii)=W(ii);
end
y= Is
end
sorrry i receive the same message
Output argument "z" (and possibly others) not assigned a value in the execution with "triangle_basisn"
function.
Did you read @Walter Roberson 's and my comment ? Negative values of the independent variable phi are not covered in your if-statement, and thus no value is assigned to z:
if kk==1
z=phi./dftm;
elseif ( phi >= Phin(kk-1) ) & ( phi <=Phin(kk));
z=(phi-Phin(kk-1))./dftm;
elseif (phi >= Phin(kk) ) & (phi <=Phin(kk+1));
z=(Phin(kk+1)-phi)./dftm;
end
Yes!! this is the problem sorry i see the comment later

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange

Produkte

Version

R2024b

Gefragt:

am 25 Nov. 2024

Bearbeitet:

am 26 Nov. 2024

Community Treasure Hunt

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

Start Hunting!

Translated by