フィルターのクリア

New Recursion Issue

3 ビュー (過去 30 日間)
Andrew
Andrew 2011 年 2 月 11 日
Hi everyone,
Having issues with my same program just I can't seem to see the error again since i have all the conditions I think...
Codes:
main:
close all
clear all
clc
theta = [-pi:pi/100:pi]';
plotValues = cos(theta);
lamda = [0:(2*pi)/100:(2*pi)]';
set1 = pnmnew(1,1,theta,1);
set2 = pnmnew(3,1,theta,1);
set3 = pnmnew(5,1,theta,1);
set4 = pnmnew(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 = pnmnew(1,1,theta,0);
set2non = pnmnew(3,1,theta,0);
set3non = pnmnew(5,1,theta,0);
set4non = pnmnew(7,1,theta,0);
figure
hold on
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 = pnmnew(4,0,theta,1)*cos(0*lamda);
SnmZ = pnm(4,0,theta,1)*sin(0*lamda);
pnm:
function [ values ] = pnmnew( n,m,theta,norm )
if ( norm == 0 )
if ( m == 0)
syms q
diffe = (cos(q)^2-1)^n;
diffe = diff(diffe,n);
diffe = subs(diffe,q,theta);
values = (1/((2^n)*factorial(n)))* diffe;
else
syms t
differ = (cos(t)^2-1)^n;
differ = diff (differ,n+m);
differ = subs(differ,t,theta);
values = (1/((2^n)*factorial(n))).*((1-cos(theta).^2).^(m/2)).*differ;
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==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)-(wnmB)^(-1)*pnm(n-2,m,theta,norm));
elseif ( m==0 && n~=0)
values = (-(n-1)/n)*pnm(n-2,m,theta,norm)+((2*n-1)/n)*cos(theta)*pnm(n-1,m,theta,norm);
elseif (n == m && (n~=1 && m~=1))
wmm = sqrt((2*m-1)/(2*m));
values = wmm.*(1-cos(theta).^2).^(1/2)*pnm(m-1,m-1,theta,norm);
elseif (n <0 || m < 0)
values = 1;
elseif ( n ~= m )
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)-(wnmB)^(-1)*pnm(n-2,m,theta,norm));
end
end
end
I'm pretty sure the issue is something to do with m = 0 and n = 0 but I already have my condition for that so I don't know whats wrong. Matlab just give sme the recursion limit error

採用された回答

Oleg Komarov
Oleg Komarov 2011 年 2 月 11 日
Ok, you created pnmnew, but inside you call pnm, which in my case still doesn't handle negative m or n as I pointed out in 1227-recursion-issue
Oleg
  1 件のコメント
Andrew
Andrew 2011 年 2 月 11 日
Oh I didn't realize I was still calling pnm within my new function I changed it according to what you said last time but didn't change all my functions names. Thanks!
I'm getting the correct plots not. I might have to post again if I hit another condition error though. xD
Thanks for the help

サインインしてコメントする。

その他の回答 (1 件)

Andrew
Andrew 2011 年 2 月 11 日
Bumpp
  1 件のコメント
Walter Roberson
Walter Roberson 2011 年 2 月 11 日
See solution in http://www.mathworks.com/matlabcentral/answers/1235-new-recursion-issue

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeNumbers and Precision についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by