Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

Program 3 : (sum of function 0.

2^n )

n=1:5000
f=0.2^n
s=sum(f)
disp("The sum of 0.2^n = ",s)

output:

s=sum(f)

s = 0.25

program //N-th root of unity

n=input("Enter n=")
x=poly(0,"x");
p=x^n+1
rt=roots(p)
mprintf("The %d-th root of unity are\n",n)
disp(rt)

program 9 : (find the two squar roots of -5+12j )

x=-5+12*(-1)^(1/2)
y=sqrt(x);
disp (y);

output :

disp (y);

2. + 3.i
Program 10 : (Integral transform FFT )

//Frequency components of a signal


// build a noised signal sampled at 1000hz containing pure frequencies
// at 50 and 70 Hz
sample_rate=1000;
t = -2:1/sample_rate:2;
N=size(t,'*'); //number of samples
s=sin(t);
y=fft(s);
//s is real so the fft response is conjugate symmetric and we retain only the first
N/2 points
f=sample_rate*(0:(N/2))/N; //associated frequency vector
n=size(f,'*')
clf()
subplot(211)
plot2d(t,s)
subplot(212)
a=gca();
plot2d(f,abs(y(1:n)))
a.data_bounds=[0,0;4,2000];

output :
diracdelta function

x0=-100;x1=100;
sig=input("Enter sigma=");
function II=f(x), II=1/sqrt(2*%pi*sig^2)*exp(-((x-
2)^2)/(2*sig^2))*(x+3),endfunction
X=intg(x0,x1,f);
disp("The integration is= "+string(X))

Program 4 : ∫ Pn(x).Pm(x) dx= δnm


//Legendre Polynomials Orthogonality Verification
clc;
n=input("Enter n:");
m=input("Enter m:");
a=integrate('legendre(m,0,x)*legendre(n,0,x)','x',-1,1,0.001);
mprintf('∫P%i(x)*P%i(x)dx= %f\n',m,n,a);

Output :

Enter n:3

Enter m:3

∫P3(x)*P3(x)dx= 0.285714

Plot of Pn(x)
// example 1 : plot of the 6 first Legendre polynomials on (-1,1)
x = linspace(-1,1,200)';
y = legendre(0:5, 0, x);
clf()
plot2d(x,y', leg="p0@p1@p2@p3@p4@p5@p6")
xtitle("the 6 th first Legendre polynomials")

output :
Plot Jv(x)
//Bessel Functions of the First Kind
//Plotting some Bessel Functions
clf;
x=[0:0.01:20]';
alpha=0:9;
y=besselj(alpha,x);
plot2d(x,y,leg='J0@J1@J2@J3@J4@J5@J6@J7J8@J9');
xlabel('x');
ylabel('Ja(x)');
xtitle('Some Bessel Functions of the first kind');

output :

You might also like