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

조회 수: 2 (최근 30일)
Dharmendra
Dharmendra 2012년 9월 26일
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);
>>

채택된 답변

Matt Fig
Matt Fig 2012년 9월 26일
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
Dharmendra
Dharmendra 2012년 9월 26일
Thanks you so much Mr. Matt Fig for solving my problem. Now it is working.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Jan
Jan 2012년 9월 26일
편집: Jan 2012년 9월 26일
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?!

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by