More Recursion Help Needed
Mostrar comentarios más antiguos
Hi again everyone,
I became stuck on another section of my lab saying this:
Error in ==> pnm at 6
if ((n ~= 0 && m ~= 0) || (n~=0 && m==0) || (n==0 && m~=0))
??? Output argument "values" (and maybe others) not assigned
during call to "E:\Matlab\ENGO423-Lab2\pnm.m>pnm".
Error in ==> pnm at 19
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);
Error in ==> main at 24
set2non = pnm(3,1,theta,0);
Here are my codes:
Main:
close all
clear all
clc
theta = [-pi:pi/100:pi]';
plotValues = cos(theta);
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')
set1non = pnm(1,1,theta,0);
set2non = pnm(3,1,theta,0);
%set3non = pnm(5,1,theta,0);
%set4non = pnm(7,1,theta,0);
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 ( norm == 0 && 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 (norm == 0 && n==1 && m==1)
values = sin(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) || (n==0 && m~=0) || (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
If anyone can assist me in finding my error again that would be greatly appreciated.
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Performance and Memory en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!