Double integration problem (can not use symbolic math tool box)

5 visualizaciones (últimos 30 días)
I have a function of two variable to double integrate but i can not use symbolic integration as i want to compile this to .exe file.
clc;
sig=0.5;
L=4;
k=1.0472;
k_sig=k*sig;
kls=k*ls;
er=3.5;
theta=(0:10:70)';
g=length(theta);
Q=zeros(g,1);
for i=1:g;
cs=cosd(theta(i)); s=sind(theta(i)); s2=s.*s; cs2=cs.*cs;
ks=k.*sig; kL=k.*L; ks2=ks.*ks; kL2=kL.*kL;
%(*Integration variables*)
r2=@(r)(r.*r); sf=@(phi)sin(phi); csf=@(phi)cos(phi);
rx=@(r,phi)(r.*csf(phi)); ry=@(r,phi)(r.*sf(phi));
Wmh=0; Wnh=0.0;
for n=1:4;
for m=1:4;
wn=@(r,phi)(n.*kL2./(n.*n + kL2.*((rx(r,phi) - s).^2...
+ ry(r,phi).^2))^1.5);
wm=@(r,phi)(m.*kL2./(m.*m + kL2.*((rx(r,phi) + s).^2...
+ ry(r,phi).^2))^1.5);
vhmn=((ks2.*cs2).^(n+m))./(factorial(m).*factorial(n));
Wm=@(r,phi)(vhmn.*wn(r,phi).*wm(r,phi));
Wmh=@(r,phi)(Wmh(r,phi)+Wm(r,phi));
end
end
Wnh=@(r,phi)(Wnh(r,phi)+Wmh(r,phi));
VH=@(r,phi)(Wnh(r,phi).*r);
%% Double Integration
Q(i)=quad2d(VH,0,1,0,pi/4);
end
HV=10*log10(Q);
table=[theta HV]
This is giving Error:
Error:
Subscript indices must either be real positive integers or logicals.
Error in @(r,phi)(Wnh(r,phi)+Wmh(r,phi))
Error in @(r,phi)(Wnh(r,phi).*r)
Error in quad2d/tensor (line 344)
Z = FUN(X,Y); NFE = NFE + 1;
Error in quad2d (line 168)
[Qsub,esub] = tensor(thetaL,thetaR,phiB,phiT);
Error in Untitled1 (line 32)
Q(i)=quad2d(VH,0,1,0,pi/4);
>>

Respuesta aceptada

Matt Fig
Matt Fig el 26 de Sept. de 2012
You have a couple of errors. One is you didn't define the base recursion functions to be functions but doubles - this is where your error comes from. Second you didn't use .^ everywhere instead of ^.
clc;
sig=0.5;
L=4;
k=1.0472;
k_sig=k*sig;
kls=k*ls;
er=3.5;
theta=(0:10:70)';
g=length(theta);
Q=zeros(g,1);
for i=1:g;
cs=cosd(theta(i)); s=sind(theta(i)); s2=s.*s; cs2=cs.*cs;
ks=k.*sig; kL=k.*L; ks2=ks.*ks; kL2=kL.*kL;
%(*Integration variables*)
r2=@(r)(r.*r); sf=@(phi)sin(phi); csf=@(phi)cos(phi);
rx=@(r,phi)(r.*csf(phi)); ry=@(r,phi)(r.*sf(phi));
Wmh=@(x,y) 0; Wnh=@(x,y) 0*x;
for n=1:4;
for m=1:4;
wn=@(r,phi)(n.*kL2./(n.*n + kL2.*((rx(r,phi) - s).^2 ...
+ ry(r,phi).^2)).^1.5);
wm=@(r,phi)(m.*kL2./(m.*m + kL2.*((rx(r,phi) + s).^2 ...
+ ry(r,phi).^2)).^1.5);
vhmn=((ks2.*cs2).^(n+m))./(factorial(m).*factorial(n));
Wm=@(r,phi)(vhmn.*wn(r,phi).*wm(r,phi));
Wmh=@(r,phi)(Wmh(r,phi)+Wm(r,phi));
end
end
Wnh=@(r,phi)(Wnh(r,phi)+Wmh(r,phi));
VH=@(r,phi)(Wnh(r,phi).*r);
%%Double Integration
Q(i)=quad2d(VH,0,1,0,pi/4);
end
  1 comentario
Dharmendra
Dharmendra el 26 de Sept. de 2012
Thanks you so much Mr. Matt Fig for solving my problem. Now it is working.

Iniciar sesión para comentar.

Más respuestas (1)

Jan
Jan el 26 de Sept. de 2012
Editada: Jan el 26 de Sept. de 2012
Initially you defined:
Wnh = 0.0;
Later you replace this by:
Wnh = @(r,phi)(Wnh(r,phi)+Wmh(r,phi));
Now in the first call of "Wnh(r,phi)" the term "Wnh" is a scalar array and "r,phi" is interpreted as index. And indices must be positive integers.
Are you sure you want to define the function handle Wnh recursively?!

Categorías

Más información sobre Programming en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by