필터 지우기
필터 지우기

Recursion Help ... Again...

조회 수: 1 (최근 30일)
Andrew
Andrew 2011년 2월 11일
Hi again everyone, I am still trying to fix my recursion... If anyone could help me with these conditions that would be great I seem to keep on getting infinite recursions.
My codes are below:
Main:
close all
clear all
clc
theta = [-pi:pi/100:pi]';
plotValues = cos(theta);
lamda = [0:(2*pi)/100:(2*pi)]';
set1 = pnm(1,1,theta,1);
set2 = pnm(3,1,theta,1);
set3 = pnm(5,1,theta,1);
set4 = pnm(7,1,theta,1);
hold on
plot(plotValues,set1,'g');
plot(plotValues,set2,'r');
plot(plotValues,set3,'m');
plot(plotValues,set4,'b');
axis([-1 1 -4 4]);
legend('n=1; m=1','n=3; m=1', 'n=5; m=1', 'n=7; m=1')
hold off
%set1non = pnm(1,1,theta,0);
%set2non = pnm(3,1,theta,0);
%set3non = pnm(5,1,theta,0);
%set4non = pnm(7,1,theta,0);
%hold off
%hold on
%figure
%plot(plotValues,set1non,'g');
%plot(plotValues,set2non,'r');
%plot(plotValues,set3non,'m');
%plot(plotValues,set4non,'b');
%axis([-1 1 -4 4]);
%legend('n=1; m=1','n=3; m=1', 'n=5; m=1', 'n=7; m=1')
RnmZ = pnm(4,0,theta,1)*cos(0*lamda);
SnmZ = pnm(4,0,theta,1)*sin(0*lamda);
PNM:
function [ values ] = pnm( n,m,theta,norm )
%What to do...
if ((n ~= 0 && m ~= 0) || (n~=0 && m==0) || (n==0 && m~=0))
if (norm == 0 )
if (m >= 2)
pnmCurrentn = 2*(m-1)*((cos(theta)/sqrt(1-cos(theta)^2)))*pnm(n,m-1,theta,norm)-(n-m+2)*(n+m-1)*pnm(n,m-2,theta,norm);
values = pnmCurrentn;
elseif (norm == 0 && m == 0)
pn = -((n-1)/n)*pnm(n-2,0,theta,norm)+((2*n-1)/n)*(cos(theta))*pnm(n-1,0,theta,norm);
values = pn;
elseif ( n >= m+2)
pnmCurrentn = ((2*n-1)/(n-m)).*cos(theta).*pnm(n-1,m,theta,norm)-((n+m-1)/(n-m))*pnm(n-2,m,theta,norm);
values = pnmCurrentn;
elseif (n==1 && m==1)
values = sin(theta);
elseif ( n==2 && m ==1 )
values = 3.*sin(theta).*cos(theta);
end
elseif ( norm == 1)
if ( n == 1 && m == 1)
w11 = sqrt(3);
values = w11*sqrt((1-cos(theta).^2))*pnm(m-1,m-1,theta,norm);
elseif (( n==0 && m==0))
values = 1;
elseif ( n == m)
wmm = sqrt((2*m-1)/(2*m));
values = wmm.*(1-cos(theta).^2).^(1/2)*pnm(m-1,m-1,theta,norm);
elseif (n~=m || (n~=0 && m==0))
wnm = sqrt(((2*n+1)*(2*n-1))/((n+m)*(n-m)));
wnmB = sqrt(((2*(n-1)+1)*(2*(n-1)-1))/(((n-1)+m)*((n-1)-m)));
values = wnm*(cos(theta).*pnm(n-1,m,theta,norm)-inv(wnmB)*pnm(n-2,m,theta,norm));
end
end
elseif ((n == 0 && m == 0))
if (norm ~= 1)
values = 1;
elseif (norm == 1)
values = 1;
end
end
end

채택된 답변

Amin Bashi
Amin Bashi 2011년 2월 11일
check this codes
elseif (norm == 0 && m == 0)
pn = -((n-1)/n)*pnm(n-2,0,theta,norm)+((2*n-1)/n)*(cos(theta))*pnm(n-1,0,theta,norm);
values = pn;
these not terminate bcos n always decrease. define a termination condition for n!
  댓글 수: 2
Andrew
Andrew 2011년 2월 11일
Actually, currently I'm trying to fix the section of elseif(norm == 1) I will keep that in mind when I begin doing the section with normalization I would like to finish the normalization part which I've been stuck on for a while though. If you have any information my code produces an error
Andrew
Andrew 2011년 2월 11일
at this part:
elseif (n~=m || (n~=0 && m==0))
wnm = sqrt(((2*n+1)*(2*n-1))/((n+m)*(n-m)));
wnmB = sqrt(((2*(n-1)+1)*(2*(n-1)-1))/(((n-1)+m)*((n-1)-m)));
values = wnm*(cos(theta).*pnm(n-1,m,theta,norm)-inv(wnmB)*pnm(n-2,m,theta,norm));
end

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Direction of Arrival Estimation에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by