//Frequency components of a signal //Build a noised signal samples at 1000Hz clc clf sample_rate=1000 t=-3: 1/sample_rate:3 N=size(t,'*');//number of samples s=exp(-t^2) y=fft(s)//s is real so fft response is conjugate symmetric and we retain only the first N f=sample_rate*(0:(N/2))/N; n=size(f,'*') subplot(2,1,1) plot2d(t,s) subplot(2,1,2) a=gca(); plot2d(f,abs(y(1:n))) a.data_bounds=[0,0;20,200] --> exec('C:\Users\asekh\Documents\n th roots of unity.sce', -1) Enter n=2 "rt is =" 0. + i 0. - i "rt1 is=" 2. + 3.i --> exec('C:\Users\asekh\Documents\n th roots of unity.sce', -1) Enter n=3 "rt is =" -1. + 0.i 0.5 + 0.8660254i 0.5 - 0.8660254i "rt1 is=" 2. + 3.i --> exec('C:\Users\asekh\Documents\n th roots of unity.sce', -1) Enter n=4 "rt is =" -0.7071068 + 0.7071068i -0.7071068 - 0.7071068i 0.7071068 + 0.7071068i 0.7071068 - 0.7071068i "rt1 is=" 2. + 3.i //Plotting Legendre Polynomial clc;clf x=-1:0.01:1 disp("Program to plot Legendre Polynomial") leg=legendre(0:7,0,x) plot2d(x',leg',leg="P0@P1@P2@P 3@P4@P5@P6@P7@") xlabel("x") ylabel("Pn(x)") //Orthogonality of Legendre Polynomial clf disp("Program for Orhtogonality of Legendre POlynomial") n1=input("Please enter the value of n1=") n2=input("Please enter the value of n2=") function r=orth(x) r=legendre(n1,0,x)*legendre(n2,0,x) endfunction z=integrate('orth','x',-1,1,0.001) if z<0.001 then z=0 else disp("2/(2*n+1)is") disp("(2/(2*n2)+1)") end disp("The answer is "+string(z)) //Plot first six bessel functions of first kind clf x=linspace(0,10,100)'; n=0:5; y=besselj(n,x); plot2d(x,y,leg="J0@J1@J2@J3@J4 @J5"); xtitle("First six Bessel functions of first kind","x","Jn(x)") clc clf; function dy=f(x, y) dy(1)=y(2) dy(2)=-y(1)-2*y(2) endfunction x=0:0.01:10 y0=[0;5] y=ode(y0,0,x,f) plot2d(x,y(1,:),2) plot2d(x,y(2,:),3) xlabel("x axis") ylabel("y axis") xtitle("solution of differential equation") h1=legend("y(1)","y(2) or, dy/dt") clc clf; function dy=f(x, y) dy(1)=y(2) dy(2)=-exp(-x)*y(1)+x^2 endfunction t=0:0.01:10 y0=[0;0] y=ode(y0,0,t,f) plot2d(t,y(1,:),2) plot2d(t,y(2,:),3) xlabel("x axis") ylabel("y axis") xtitle("solution of differential equation") h1=legend("y(t)","dy/dt") clc clf; function dy=f(t, y) dy(1)=y(2) dy(2)=-y(1)-exp(-t)*y(1) endfunction t=0:0.01:10 y0=[0;5] y=ode(y0,0,t,f) plot2d(t,y(1,:),2) plot2d(t,y(2,:),3) xlabel("t axis") ylabel("y axis") xtitle("solution of differential equation") h1=legend("y(1)","y(2) or, dy/dt") //Recurrence relation of Bessel Function //2nJn(x)'/x=J(n-1)(x)+J(n+1)(x) clf x=-5:0.1:5 n=input("Enter n=") function R=rhs(x) R=(2*n/x)*besselj(n,x) endfunction function L=lhs(x) L=besselj(n-1,x)+besselj(n+1,x) endfunction value_lhs=feval(x,lhs) value_rhs=feval(x,rhs) plot(x,value_rhs,'*b') plot(x,value_lhs,'g') l=legend('RHS','LHS') title("Recurrence Relation") xlabel("x") ylabel("J","+string(n)") clf clc funcprot(0) function dy=f(x, y) dy=exp(-x); endfunction x0=0; y0=0; x=0:0.1:20; y=ode(x0,y0,x,f); plot(x,y); xlabel('x'); ylabel('y'); xtitle('x v/s f(x,y)'); legend("dy/dx =exp(-x)") clf funcprot(0) s=input("Enter sigma=") function y=dirac(x) y=(1/sqrt(2*(%pi)*(s^2)))*(%e)^(((x-2)^2)/(2*(s^2)))*(x+3) endfunction I=integrate('dirac','x',0,4) disp(I) clc clf funcprot(0) deff('a=f(x)','a=1') function a=period(x) L=1 if (x>=-L)&(x<=0) then a=-f(x) elseif(x>=0)&(x<=L) then a=f(x) elseif(x>=L) then x_new=x-2*L a=period(x_new) elseif(x<=-L) then x_new=x+2*L a=period(x_new) end endfunction xlabel("Time") ylabel("Function") xgrid L=1 n=50 a0=(1/L)*intg(-L,L,period,1e-2) mprintf('a_0=%f\n',a0) for i=1:n function b=period1(x, f) b=period(x)*cos(i*%pi*x/L) endfunction function c=period2(x, f) c=period(x)*sin(i*%pi*x/L) endfunction A(i)=(1/L)*intg(-L,L,period1,1e-2) mprintf('coefficient of cos():a_%i=%f\t',i,A(i)) B(i)=(1/L)*intg(-L,L,period2,1e-2) mprintf('coefficient of sin():b_%i=%f\t',i,B(i)) end function series=solution(x) series = a0/2 for i=1:n series=series+A(i)*cos(i*%pi*x/L)+B(i)*sin(i*%pi*x/L) end endfunction x=-1:0.001:1 plot(x,solution(x),'r') plot(x,period,'b') plot(solution(x),period,'g') xlabel('X-Axis') ylabel('Y-Axis') //Plot first six modified bessel functions of first kind clf x=linspace(0,10,100)'; n=0:5; y=besseli(n,x); plot2d(x,y,leg="I0@I1@I2@I3@I4 @I5"); xtitle("First six modified Bessel functions of first kind","x","In(x)") clc clf a=0; b=2*%pi; sigma=0.1; m=200; xd=linspace(a,b,m)'; yd=sin(xd)+grand(xd,"nor",0,sigm a); n=6; x=linspace(a,b,n)'; [y,d]=lsq_splin(xd,yd,x); ye=sin(xd); ys=interp(xd,x,y,d); plot2d(xd,[ye,yd,ys],style=[2,2,3],leg="Exact function experimental measure (Gaussian fitted spline)") xtitle("Least square fitting")