S
Shashidhar Patil
here is the code
#include<iostream.h>
#include<math.h>
#include<conio.h>
class legendre
{
private:
int c,b,z,zz,xx,yy,fact;
double a,nt,x,y,aa,final,bb,cc;
double sum1=0;
public:
int factorial(int n)
{
if (n==0)
return 1;
else
{
fact=n*factorial(n-1);
return fact;
}
}
// legendre();
void calculate(int l,int m,double theta)
{
a=(2*l+1)/2;
b=1- m%1;
c=1+ m%1;
zz=factorial(l);
xx=factorial(c);
yy=factorial(z);
bb=factorial(b)/zz;
cc=factorial(c)/zz;
nt=sqrt(a*bb*cc);
for(int q=0; q<=b/2; q++)
{
z=2*l-2*q;
x=z/(factorial(l-q)*factorial(q));
y=yy/(xx*factorial(z-c));
sum1+=((pow(-1,l+q))*x*y*(pow(cos(theta),b-2*q)));
}
aa=nt*(pow(sin(theta),m)/pow(2,l));
final=aa*sum1;
cout<<"the value of the expression : "<<final<<endl;
}
};
void main()
{
int l,m;
double theta;
cout<<"enter the values for l, m and theta: "<<endl;
cin>>l>>m>>theta;
legendre expression;
expression.calculate(l,m,theta);
getch();
}
#include<iostream.h>
#include<math.h>
#include<conio.h>
class legendre
{
private:
int c,b,z,zz,xx,yy,fact;
double a,nt,x,y,aa,final,bb,cc;
double sum1=0;
public:
int factorial(int n)
{
if (n==0)
return 1;
else
{
fact=n*factorial(n-1);
return fact;
}
}
// legendre();
void calculate(int l,int m,double theta)
{
a=(2*l+1)/2;
b=1- m%1;
c=1+ m%1;
zz=factorial(l);
xx=factorial(c);
yy=factorial(z);
bb=factorial(b)/zz;
cc=factorial(c)/zz;
nt=sqrt(a*bb*cc);
for(int q=0; q<=b/2; q++)
{
z=2*l-2*q;
x=z/(factorial(l-q)*factorial(q));
y=yy/(xx*factorial(z-c));
sum1+=((pow(-1,l+q))*x*y*(pow(cos(theta),b-2*q)));
}
aa=nt*(pow(sin(theta),m)/pow(2,l));
final=aa*sum1;
cout<<"the value of the expression : "<<final<<endl;
}
};
void main()
{
int l,m;
double theta;
cout<<"enter the values for l, m and theta: "<<endl;
cin>>l>>m>>theta;
legendre expression;
expression.calculate(l,m,theta);
getch();
}