Uploaded by b.malyadri pavan ganesh

AOD final

advertisement
Fourier series:
clc
clear all
clf
syms x n
y=input('enter the function:');
a=input('enter the lower lmit:');
b=input('enter the upper imit:');
L=(b-a)/2;
a0=(1/L)*int(y,x,a,b);
f=a0/2
for n=1:20
an=(1/L)*int(y*cos(n*pi*x/L),x,a,b)
bn=(1/L)*int(y*sin(n*pi*x/L),x,a,b)
f=f+(an*cos(n*pi*x/L)+bn*sin(n*pi*x/L))
end
ezplot(y,[a,b])
hold on
ezplot(f,[a,b])
Harmonic analysis:
clear all
clc
syms t
x=input('Enter the equally spaced values of x: ');
y=input('Enter the values of y=f(x): ');
m=input('Enter the number of harmonics required: ');
n=length(x);a=x(1);b=x(n);
h=x(2)-x(1);
L=(b-a+h)/2;
theta=pi*x/L;
a0=(2/n)*sum(y)
Fx=a0/2;
x1=linspace(a,b,100);
for i=1:m
an=(2/n)*sum(y.*cos(i*theta));
bn=(2/n)*sum(y.*sin(i*theta));
disp(strcat('a',num2str(i),'=',num2str(an)))
disp(strcat('b',num2str(i),'=',num2str(bn)))
Fx=Fx+an*cos(i*pi*t/L)+bn*sin(i*pi*t/L);
subplot(2,3,i)
Fx=vpa(Fx,m);
Fx1=subs(Fx,t,x1);
plot(x1,Fx1);
hold on
plot(x,y);
title(['Fourier Series with ',num2str(i),'harmonics'])
hold off;
end
disp(strcat('Fourier series with',num2str(i),'harmonicis:',char(Fx)));
Matrix:
Characteristic polynomial, its roots, eigen values & vectors, transpose &
inverse eigen values, eigen values equation, verification D=P-1AP
clc
clear all
A=input('Enter the matrix A:');
polynomial=poly(A)
roots_of_A=roots(polynomial)
eigval=eig(A)
[V,D]=eig(A)
eig_oftranspose_of_A=eig(A')
eig_invA=eig(inv(A))
B=A^3+6*A^2-5*A+7*eye(size(A))
eig(B)
inv(V)*A*V
Characteristic polynomial, it’s roots, eigen values & vectors, transpose &
inverse eigen values, eigen values equation:
clc
clear all
A=input('Enter the matrix A:');
polynomial=poly(A)
roots_of_A=roots(polynomial)
eigval=eig(A)
[V,D]=eig(A)
eig_oftranspose_of_A=eig(A')
eig_invA=eig(inv(A))
B=A^2+3*A+2*eye(size(A))
eig(B)
inv(V)*A*V
Diagonalize:
clc
clear all
A=input('Enter the matrix A:');
polynomial=poly(A)
roots_of_A=roots(polynomial)
eigval=eig(A)
[V,D]=eig(A)
inv(V)*A*V
Matrix method:
One variable:
clc
clear all
syms y1(t) y2(t)
A=input('enter the coefficient matrix:');
F=input('enter the non-homogenious part:');
Y=[y1;y2];
de=diff(Y)==A*Y+F;
C=Y(0)==input('enter the conditions:');
[y1(t),y2(t)]=dsolve(de,C);
y1(t)=simplify(y1(t))
y2(t)=simplify(y2(t))
subplot(1,2,1)
fplot(y1(t),[0,3])
subplot(1,2,2)
fplot(y2(t),[0,3])
Two different variables:
clc
clear all
syms x(t) y(t)
A=input('enter the coefficient matrix:');
B=input('enter the matrix B:');
Y=[x;y];
de=diff(Y,2)==A*Y+B;
C=Y(0)==input('enter the 1st condition:');
D=diff(Y);
E=D(0)==input('enter the 2nd condition:');
[x(t),y(t)]=dsolve(de,C,E);
x(t)=simplify(x(t))
y(t)=simplify(y(t))
subplot(1,2,1)
ezplot(x(t),[0,3])
subplot(1,2,2)
ezplot(y(t),[0,3])
Z-transform:
clc
clear all
syms n z
f=input('Enter the function: ');
F=ztrans(f, n, z)
simplify(F)
Inverse z-transform:
clc
clear all
syms n z
F=input('Enter the function: ');
f=iztrans(F, z, n)
simplify(f)
2nd degree non-homogenous difference equations:
clc
clear all
syms z Y n
syms y(n)
F = input('Input the coefficients [a,b,c]: ');
a=F(1);b=F(2);c=F(3);
LHS=ztrans(a*y(n+2)+b*y(n+1)+c*y(n),n,z);
nh = input('Enter the non-homogenous part f(n): ');
RHS=ztrans(nh,n,z);
IC=input('Enter the initial conditions in the form [y0,y1]:');
y0=IC(1);y1=IC(2);
newLHS=subs(LHS,{ztrans(y(n),n,z),y(0),y(1)},{Y,y0,y1});
Y=solve(newLHS-RHS,Y);
yn=iztrans(Y,z,n);
simplify(yn)
nrange=0:20;
yn=real(subs(yn,n,nrange));
stem(nrange,yn)
Download