New Recursion Issue
1 view (last 30 days)
Show older comments
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
0 Comments
Accepted Answer
Oleg Komarov
on 11 Feb 2011
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
More Answers (1)
Andrew
on 11 Feb 2011
1 Comment
Walter Roberson
on 11 Feb 2011
See solution in http://www.mathworks.com/matlabcentral/answers/1235-new-recursion-issue
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!