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 CenterFile Exchange 中查找有关 Numbers and Precision 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by