MATLAB for Engineering Students
MATLAB for Engineering Students
COMPUTING
LABORATORY
(With MATLAB)
ECL201
Name:
Reg No:
College of Engineering
Muttathara
EXP NO: 1 DATE:
OBJECTIVE:
To familiarize with the scientific computing tool using MATLAB or octave.
4. program to display the second row third column element of a 3x3 matrix as the
output
program:
clc;
clear all;
close all;
a=[1 3 3;4 5 6;7 8 9]; a(2,3)
output:
ans = 6
INFERENCE:
Familiarized with MATLAB which is basically a scientific computing tool
based on simulations.
EXP NO: 2 DATE:
OBJECTIVE:
To familiarize different functions for scientific computing with examples
program:
%plot absolute value from -3 to
3 x=[-3;0.1;3] %array fro -3 to 3
y=abs(x); %absolute value in y
subplot(2,2,1);
plot(x,y)
xlabel('x');
ylabel('y');
subplot(2,2,2);
m =-abs(x);
plot(x,m,'c')
xlabel('x');
ylabel('y');
subplot(2,2,3);
n=abs(x);
plot(x,n)
hold on;
b=-abs(x);
plot(x,b);
hold off;
xlabel('x');
ylabel('y');
2. Create a complex number 5+4i, extract the real and imaginary parts and compute
the magnitude of the vector using built in functions.
Program:
z=complex(5,4);
disp('Real Part');
a=real(z)
disp('Imaginary Part');
b=imag(z)
disp('Magnitude');
abs(z)
output:
Real Part = 5
Imaginary Part = 4
Magnitude = 6.4031
3. Represent the complex exponential form epi+ i as rectangular form and find the
real part, magnitude and the angle of the vector (both in degree and radians).
PROGRAM:
z=exp(pi*i);
disp('Complex number in rectangular form');
disp('Real Part');
a=real(z)
disp('Magnitude');
mag=abs(z)
disp('Angle in radians');
ang=angle(z)
disp('Angle in degree');
ang_deg=ang*(180/pi)
output:
Complex number in rectangular
form z = -1.0000e+0.0000i
Real
Part a =
-1
Magnitude
mag = 1
Angle in radians
ang = 3.1416
Angle in degree
ang_deg = 180
program:
x=[-5:0.001:5];
y=sinc(x);
subplot(2,2,1)
plot(x,y)
t=-9:0.01:9;
y=sin(t);
x=cos(t);
subplot(2,2,2)
plot(x,y)
t1=0:0.001:1
y=exp(-5*t1);
subplot(2,2,3)
plot(t1,y);
5. Plot sinew aves of frequency 50 and 100 Hz on the same figure window.
program:
f=50;
t=0:0.0002:0.1;
y=sin(2*pi*f*t);
plot(t,y);
grid on;
hold on;
f=100;
t=0:0.0002:0.1;
y=sin(2*pi*f*t);
plot(t,y);
hold off;
OUTPUT
6. Replace the given code w ith vectorized code for fast
computing (a)This code computes the sine of 1,001 values
ranging from 0 to 10:
clc;
clear all;
close all;
i = 0;
for t = 0:.01:10 i
= i + 1;
y(i) = sin(t);
end
disp(y);
(b)
clc;
clear all;
close all;
r=[1:4];
h=[1:4];
for i=1:4
volume(i) = pi*r(i)*r(i)*h(i); end
disp(volume);
PROGRAM:
(a)
t = 0:.01:10;
y = sin(t);
disp(y);
(b)
clc;
clear all;
close all;
r=[1:4];
h=[1:4];
volume = pi*r.^2.*h;
disp(volume);
7. Execute a script (.m file) to obtain the dot product and the cross product of tw o
vectors a and b, w here a = (1 5 6) and b = (2 3 8).
PROGRAM:
a = [1 5 6];
b = [2 3 8];
dotpro=dot(a,b)
crosspro=cross(a,b)
output:
dotpro = 65
crosspro =
22 4 -7
8. Simplify the expression and express the complex number in rectangular and polar
form (a.) y =0.5+ j 6+3.5 e j0.6+(3+ j 6)e j0.3 pi .
(3+ j 4)(5+ j 2)(2<60)
(b.) z=
(3+ j 6)(1+ j 2)
(a.) PROGRAM:
clc;
clear all;
close all;
Z1 = 0.5;
Z2 =6*j;
Z3 = 3.5*exp(j*0.6); Z4
= 3+6*j;
Z5 = exp(j*0.3*pi);
disp('Z in rectangular form is');
Z_rect = Z1+Z2+Z3+(Z4*Z5);
Z_rect
Z_mag = abs (Z_rect); % magnitude of Z
Z_angle = angle(Z_rect)*(180/pi); % Angle in degrees
disp('complex number Z in polar form, mag, phase');
Z_polar = [Z_mag, Z_angle]
OUTPUT:
Z in rectangular form is
Z_rect =0.2979 +13.9300i
complex number Z in polar form, mag, phase
Z_polar =13.9332 88.7748
(b) PROGRAM
clc;
clear all;
Z1=3+4*j;
Z2=5+2*j;
theta = 60*(pi/180); % angle in radians
Z3 = 2*exp(j*theta);
Z4 = 3+6*j;
Z5 = 1+2*j;
disp('Z in rectangular form is');
Z_rect = Z1*Z2*Z3/(Z4*Z5);
Z_rect
Z_mag = abs (Z_rect); % magnitude of Z
Z_angle = angle(Z_rect)*(180/pi); % Angle in degrees
disp('complex number Z in polar form, mag, phase');
Z_polar = [Z_mag, Z_angle]
OUTPUT:
Z in rectangular form is
Z_rect =3.5546 + 0.5035i
complex number Z in polar form, mag, phase
Z_polar = 3.5901 8.0616
INFERENCE:
Familiarized with basic arithmetic functions for scientific computing and used
vectorized computing for fast scientific applications.
EXP NO: 3 DATE:
OBJECTIVE:
To familiarize with the realization of arrays and matrixes and their visualization
using plotting functions and GUI.
1. The voltage, v, across a resistance is given as (Ohm’s Law ), v=iR , w here i is the
current and R the resistance. The pow er dissipated in resistor R is given by the
expression
P = i2R.
If R = 10 Ohms and the current is increased from 0 to 10 A w ith increments of 2A, w rite a
MATLAB program to generate a table of current, voltage and pow er dissipation.
PROGRAM:
clc;
clear all;
close all;
R=10; % Resistance value
i=[0:2:10]; % Generate current values
v=i.*R; % array multiplication to obtain voltage
p=(i.^2)*R; % power calculation
sol=[i;v;p] % current, voltage and power values are printed
OUTPUT:
sol =
0 2 4 6 8 10
0 20 40 60 80 100
0 40 160 360 640 1000
PROGRAM:
clc;
clear all;
close all;
a=input('enter a');
b=input('enter b');
c=input('enter c');
i = b^2 - 4*a*c;
if i> 0
srint = sqrt(i);
x1= (-b + srint)/(2*a); x2=
(-b - srint)/(2*a); elseif i
== 0
x1= -b/(2*a);
x2= x1; elseif
i< 0
srint = sqrt(-i);
p1 = -b/(2*a); p2
= srint/(2*a); x1 =
p1+p2*j; x2 = p1-
p2*j;
end
rt =[x1;x2];
OUTPUT:
rt =
1.0000 + 1.4142i
1.0000 – 1.4142i
3. Create two separate row vectors(arrays) a and b that contains elements from 1 to
10. Create an array of complex numbers z w ith a as the real part and b as the
imaginary part. Find the sum and complex conjugate of the array z.
PROGRAM:
clc;
clear all;
close all;
a = [1:10];
b = [1:10];
z = complex(a,b);
A = sum(z);
complex_conjugate = conj(z);
OUTPUT:
A =55.0000 +55.0000i
complex_conjugate =
Columns 1 through 4
1.0000 - 1.0000i 2.0000 - 2.0000i 3.0000 - 3.0000i 4.0000 - 4.0000i
Columns 5 through 8
5.0000 - 5.0000i 6.0000 - 6.0000i 7.0000 - 7.0000i 8.0000 - 8.0000i
Columns 9 through 10
9.0000 - 9.0000i 10.0000 -10.0000i
PROGRAM:
clc;
clear all;
close all;
c=[1+j 2-2*j; 3+2*j 4+3*j] s=sum(c);
S1=sum(s);
trans = c.';
conjugate_trans=c';
OUTPUT:
S1 =10.0000 + 4.0000i
trans =
1.0000 + 1.0000i 3.0000 + 2.0000i
2.0000 - 2.0000i 4.0000 + 3.0000i
conjugate_trans =
1.0000 - 1.0000i 3.0000 - 2.0000i
2.0000 + 2.0000i 4.0000 - 3.0000i
5. Create an image that consists of alternate row s of black and white pixels
without using the inbuilt function ‘image’.
PROGRAM:
clc;
clear all;
close
all;
row = 126;
col = 126;
img = zeros(row,
col); i=[1:2:125];
img(i, :) = 0;
k=[2:2:126];
img(k, :) = 1;
figure;
imshow(img)
;
OUTPUT:
6.Create amatrixof order 256 x 256 with some random values in the range [1,
80]. Display the corresponding image on the screen with colorbar.
PROGRAM:
C = randi(80,256,256);
image(C);
colormap('default')
colorbar
OUTPUT:
7. Check w hether a matrix inverse exists, and if exists, find the inverse.
PROGRAM:
clc; clear
all; close
all;
A=input('enter the matrix');
%inverse of A exists only if matrix is square and non singular [m n]=
size(A);%check the no. of rows and columns
if m==n
if det(A)==0 %matrix is singular
disp('Inverse does not exist'); else
inv_A=inv(A); disp('Inverse
is') disp(inv_A);
end
else disp('Matrix is not a square matrix');
end
INPUT:
[0 1 2;1 2 3; 3 1 1]
OUTPUT:
Inverse is
0.5000 -0.5000 0.5000
-4.0000 3.0000 -1.0000
2.5000 -1.5000 0.5000
PROGRAM:
clc;
clear all;
close all;
A=input('enter the A matrix');
B=input('enter the B matrix');
[m n]=size(A); %m rows and n columns
C=[A B];
if rank(A)==rank(C)
if rank(A)==n %n is the no. of unknowns
disp('The system has unique solution');
z1=inv(A)*B
else
if rank(A)<n %n is the no. of unknowns
disp('The system has infinite no.of solutions');
en
d
en
d disp('The system has no solution');
els
e
end
if B==0 %Homogeneous system of equations, AX=0
disp('The trivial solution is');
z1=0
end
OUTPUT:
(a)
The system has unique solution z1 =
10.0000
-1.8000
-5.6000
(b)
The system has infinite no.of solutions
(c)
The system has infinite no.of solutions
The trivial solution is
z1 =0
9. Show that the sum of the eigen values is equal to the trace of the matrix and the
product of the eigen values gives the determinant of the matrix.
PROGRAM:
clc;
clear all;
close all;
A=input('enter the matrix');
Eig_values=eig(A);
Detr=det(A)
p=prod(Eig_values)
T=trace(A) %sum of diagonal elements of A
S=sum(Eig_values)
INPUT:
[-2 2 -3;2 1 -6;-1 -2 0]
OUTPUT:
Detr =45
p =45.0000
T =-1
S =-1.0000
10. Show that AV=VD, w here D is the eigen values and V is the eigen vectors of the
square matrix
A. From this relation, represent A matrix using eigen value decomposition.
PROGRAM:
clc;
clear all;
close all;
A=input('enter the matrix');
[V D]=eig(A);
Eig_values=diag(D); %verifying AV = VD
LHS=A*V;
RHS=V*D;
Difference=LHS-RHS;
A_approximate= V*D*inv(V);
Diff=A-A_approximate;
INPUT:
[-2 2 -3;2 1 -6;-1 -2 0]
OUTPUT:
A_approximate =
-2.0000 2.0000 -3.0000
2.0000 1.0000 -6.0000
-1.0000 -2.0000 -0.0000
(
−2 2 −3
11. For the matrix A = 2 1 −6 Show that the eigen values are the roots of the
−1 −2 0
characteristic equation
PROGRAM:
A = [-2 2 -3; 2 1 -6; -1 -2 0];
p=poly(A);
Root = roots(p);
Eig_values=eig(A);
OUTPUT:
Root =
5.0000 + 0.0000i
-3.0000 + 0.0000i
-3.0000 - 0.0000i
Eig_values =
-3.0000
5.0000
-3.0000
12. Approximate the matrix A for N = 1000 w ith the help of singular value
decomposition of A as:
r
𝐀𝐀^ = ∑ ʎ𝐢𝐢𝐢𝐢𝐢𝐢 𝑽𝑽𝑽𝑽𝑽𝑽
i=0
w here Ui and Vi are the singular vectors and ʎi are the eigen values w ith ʎi<ʎjfor i> j. Plot
N N
the absolute error(ζ) betw een A and A^ as ζ = ∑∑|ai , j−ai , j|2 against r for r = 10, 50,
i=1 j=1
75, 100 , 250, 500, 750 and appreciate the plot.
PROGRAM:
clc;
clear all;
close all;
M=1050;
N=1000;
A=randi(10,M,N);
[U,S,V] = svd(A); % U is M x M matrix , V is N x N matrix and S is M x N Diagonal
matrix
M1=U*S*V';
vtrans = V';
r=[10 50 75 100 250 500 750 1000];
for i=1:8
U1=U(:,[1:r(i)]);
V1trans=vtrans([1:r(i)],:);
S1=S([1:r(i)],[1:r(i)]);
M2=U1*S1*V1trans;
sum1=0;
for j=1:M
for k=1:N
sum1 =sum1+(abs(A(j,k)-M2(j,k)))^2;
end
end
errors(i)=sum1;
end
plot(r, errors);
title('Plot of error');
xlabel('values of r')
ylabel('absolute error');
OUTPUT:
13.find the solution of system of linear equations.
2x-3y+4z =- 2
x+y-3z = 5
y+5z = 12
PROGRAM:
%solution of system of linear equations
eqn1 = input("Enter the coefficent of matrix A :");
if det(eqn1)==0
display("no solution!")
else
eqn2 = input("Enter the coefficent of matrix B :");
sol = inv(eqn1)*eqn2';
sol
en
d
OUTPUT:
Enter the coefficent of matrix A
: [2,-3,4;1,1,-3;0,1,5]
Enter the coefficent of matrix B
: [-2,5,12]
sol =
3.9714
5.1429
1.3714
OUTPUT:
Enter the matrix : [2,4,6 ; 3,5,7 ; 1,2,3]
ans = 2
ans = 10
eign =
1.0099e+01
-9.9020e-
02 3.8139e-
16
EXP NO: 4 DATE:
OBJECTIVE:
● To perform numerical differentiation and integration
output:
plot:
stem:
OUTPUT:
plot:
a) sin(t) , cos(t)
b) sinh(t) , cosh(t): both has same graph.
3. Compute the first and second derivatives of these functions using built in tools
such as grad.
PROGRAM:
t=0:0.01:10;
a=sin (t);
subplot(3,3,1)
plot(t,a)
title('sint')
b=cos (t); c=
sinh (t);
d=cosh (t);
da=gradient(a);
subplot(3,3,2)
plot(t,da)
title('first derivative of sint')
d2a=gradient(da);
subplot(3,3,3)
plot(t,d2a)
title('second derivative of
sint') db=gradient(b);
subplot(3,3,4)
plot(t,db)
title('first derivative of cost')
d2b=gradient(db);
subplot(3,3,5)
plot(t,d2b)
title('second derivative of cost')
dc=gradient(c);
subplot(3,3,6)
plot(t,dc)
title('first derivative of sinht')
d2c=gradient(dc);
subplot(3,3,7)
plot(t,d2c)
title('second derivative of sinht')
dd=gradient(d);
subplot(3,3,8)
plot(t,dd)
title('first derivative of
cosht') d2d=gradient(dd);
subplot(3,3,9)
plot(t,d2d)
title('second derivative of cosht')
OUTPUT:
4. Compute the first and second derivatives of sint, cost, sinht, cosht functions using
built in tools such as grad and plot the derivatives over the respective functions for
the vector
t = [-5, 5] w ith increment 0.01.
PROGRAM:
t=-5:0.01:5;
a=sin (t);
subplot(3,3,1)
plot(t,a)
title('sint')
b=cos (t); c=
sinh (t);
d=cosh (t);
da=gradient(a);
subplot(3,3,2)
plot(t,da)
title('first deri of sint')
d2a=gradient(da);
subplot(3,3,3)
plot(t,d2a)
title('second deri of sint')
db=gradient(b);
subplot(3,3,4)
plot(t,db)
title('first deri of cost')
d2b=gradient(db);
subplot(3,3,5)
plot(t,d2b)
title('second deri of cost')
dc=gradient(c);
subplot(3,3,6)
plot(t,dc)
title('first deri of sinht')
d2c=gradient(dc);
subplot(3,3,7)
plot(t,d2c)
title('second deri of sinht')
dd=gradient(d);
subplot(3,3,8)
plot(t,dd)
title('first deri of cosht')
d2d=gradient(dd);
subplot(3,3,9)
plot(t,d2d)
title('second deri of cosht')
OUTPUT:
5. Familiarise numerical integration tools used in matlab
a. Create the function f(x)=e−x (lnx)2. Evaluate integral from 0 to infinity
PROGRAM:
fun = @(x) exp(-x.^2).*log(x).^2; q
= integral(fun,0,Inf)
q = 1.9475
c. Create the function f(x)=ln(x). Evaluate the integral from x=0 to x=1
PROGRAM:
fun = @(x)log(x);
q1 = integral(fun,0,1)
q1 = -1.000000
6. Realize the function f(t) =4t 2 +3 and plot it for the vector [-5,5] w ith increment 0.01.
PROGRAM:
t=-5:0.01:5;
y=4*(t.^2)+3;
plot(t,y,'k','linewidth',2)
xlabel't'
ylabel'f(t)'
OUTPUT:
PLOT:
OUTPUT:
q=8
OUTPUT:
q=8
OUTPUT:
answer=8
answer=h/3*(f(a)+f(b)+4*so+2*se);
fprintf('\n The value of integration is %f',answer);
1 inf − x2
9. Comput
√2 pi ∫0e using above three methods
2
e
i) PROGRAM:
t=0:.5:1000;
yi=@(t)exp((-t.^2)/2); qi
= integral(yi,0,1000)
answeri=(1/sqrt(2*pi))*qi
OUTPUT:
answeri= 0.500
ii) PROGRAM:
t=0:.5:1000;
y=exp((-t.^2)/2);
q=trapz(t,y);
answer= (1/sqrt(2*pi))*q
OUTPUT:
answer= 0.500
iii) PROGRAM:
clc;
clear all;
f=@(x)exp((-x.^2)/2); %Change here for different function
a=input('Enter lower limit a: '); % exmple a=1 b=input('Enter
upper limit b: '); % exmple b=2
n=input('Enter the number of sub-intervals n: '); % exmple
n=16 h=(b-a)/n;
for k=1:1:n
x(k)=a+k*h;
y(k)=f(x(k));
end
so=0;se=0; for
k=1:1:n-1 if
rem(k,2)==1
so=so+y(k);%sum of odd terms
else
se=se+y(k); %sum of even
terms end
end
% Formula: (h/3)*[(y0+yn)+2*(y3+y5+..odd term)+4*(y2+y4+y6+...even
terms)]
q=h/3*(f(a)+f(b)+4*so+2*se);
answer= (1/sqrt(2*pi))*q
fprintf('\n The value of integration is %f',answer);
OUTPUT:
Enter lower limit a: 0
Enter upper limit b: 1000
Enter the number of sub-intervals n:
1000 answer =
0.4976
OUTPUT:
11. Realize the function f(t)=4t 2+3 and plot t = (-5,5) w ith increment 0.01.
program:
t = -5:0.01:5;
f1 = 4.*t.*t+3;
plot(t,f1);
ylabel("f(t)");
xlabel("t");
OUTPUT:
plot:
12. Realize the function f(t)=4t 2+3 and plot ⃗t = (-5,5) w ith increment 0.01, also plot
sin(t) and cos(t) in subplots.
Program:
t = -5:0.01:5;
f1 = 4.*t.*t+3; f2
= sin(t);
f3 = cos(t);
f4 = sinh(t);
subplot(2,2,1);
plot(t,f1,'b');
subplot(2,2,2);
plot(t,f2,'r')
subplot(2,2,3);
plot(t,f3,'g')
subplot(2,2,4);
plot(t,f4)
OUTPUT:
plot:
13. Use general integration tool and find : ∫ f (t ) .dt w here f(t)=3t 2+5.
PROGRAM:
f = @(t) 3.*(t.^2)+5; Q =
integral(f,-2,2)
OUTPUT:
Q = 36.000
1 ∞
− x2
14. compute e 2
dt using general integration tool.
√2 π ∫0
PROGRAM:
f = @(x) exp(-(x.^2)/2); fn
= integral(f,0,inf); sol =
(1/sqrt(2*pi))*fn
SOLUTION:
sol = 0.5000
15. Represent the complex exponential form epi∗i as rectangular form and find
the real part, magnitude and the angle of the vector (both in degree and radians).
program:
%Represent the complex exponential form epi∗i as rectangular form
and find the real part, magnitude and the angle of the vector (both in degree and
radians).
z=exp(pi*i);
disp('Complex number in rectangular form'); z
disp('Real Part'); a=real(z)
disp('Magnitude');
mag=abs(z) disp('Angle
in radians'); ang=angle(z)
disp('Angle in degree');
ang_deg=ang*(180/pi)
output:
Angle in radians
ang = 3.1416 Angle
in degree
ang_deg = 180
EXP NO: 5 DATE:
OBJECTIVE:
● To solve ordinary differential Equation
1. Solve the first order differential equation
dx
+2 x=0
dt
With initial condition x(0)=1
PROGRAM:
syms x(t);
eqn= diff(x,t)+ 2*x ==0;
cond= x(0)==1;
soln= dsolve(eqn,cond)
t=0:0.05:10
s=subs(soln)
plot(s)
title('Response of firt order differential
equation') xlabel('time')
OUTPUT:
soln =exp(-2*t)
2. Solve second order differential equation
d x dx
2
−t
2 +2 +2 x =e
dt dt
PROGRAM:
syms x(t) ;
eqn= diff(x,t,2) + 2*diff(x,t) + 2*x == exp(-t); soln=
dsolve(eqn);
soln=simplify(soln)
OUTPUT
soln =
exp(-t)*(C4*cos(t) + C5*sin(t) + 1)
OUTPUT:
1 – (8*sin(x/2)^4)/3
4. Solve for the current transient through an RC netw ork (w ith RC = 3)that is driven by
(a) 5V DC
(b) The signal 5𝑒𝑒 −𝑡𝑡 U(t) and plot the solutions.
(a) PROGRAM:
clc;
clear all;
close all;
symsi(t);
V=5; R=3;
C=1;
eqn= diff(i,t)+ i/(R*C) ==0; cond=
i(0)==V/R;
soln= dsolve(eqn,cond)
t=0:.05:10;
s=subs(soln); plot(t,s,'k',
'linewidth',2)
title('Current Transient of RC circuit');
xlabel('time');
ylabel('Current through capacitor');
OUTPUT:
soln =
(5*exp(-t/3))/3
PLOT:
(b)PROGRAM:
clc;
clear all;
close all;
syms i(t);
V=5*exp(-t);
R=3;
C=1;
eqn= diff(i,t)+ i/(R*C) ==diff(V,t)/R;
cond= i(0)==5/R;
soln= dsolve(eqn,cond)
t=0:.05:10;
s=subs(soln); plot(t,s,'k',
'linewidth',2)
title('Current Transient of RC circuit');
xlabel('time');
ylabel('Current through capacitor');
OUTPUT:
soln =
-(5*exp(-t)*(exp((2*t)/3) - 3))/6
5. Solve for the voltage across the capacitor of an RC netw ork that is driven by5V
DC, w ith three different time constants.
PROGRAM:
clc;
clear all;
close all;
syms vc(t);
V=5;
R1=3; %RC time constant = 3
C1=1;
TC1=R1*C1;%Time constant
eqn= diff(vc,t)==(V-vc)/(TC1);
cond= vc(0)==0;
soln1= dsolve(eqn,cond) TC2=2*TC1;%2
times the Time constant eqn=
diff(vc,t)==(V-vc)/(TC2);
soln2= dsolve(eqn,cond) TC3=3*TC1;%3
times the Time constant eqn=
diff(vc,t)==(V-vc)/(TC3);
soln3= dsolve(eqn,cond)
t=0:.05:20;
s1=subs(soln1);
s2=subs(soln2);
s3=subs(soln3);
plot(t,s1, 'r', 'linewidth',2);
hold on;
plot(t,s2, 'g', 'linewidth',2);
hold on;
plot(t,s3, 'k', 'linewidth',2);
legend('RC','2*RC','3*RC');
title('Voltage Transient of RC circuit');
xlabel('time');
ylabel('Voltage across capacitor');
OUTPUT:
soln1 =
5 - 5*exp(-t/3)
soln2
5 - 5*exp(-t/6)
=
PLOT: 5 – 5*exp(-t/9)
soln3
6. Solve the current transient through a series RLC circuit w ith R = 9, L = 1H and C =
0.05 F that is driven by
(a) 20 V DC
(b) The signal 20𝑒𝑒 −𝑡𝑡 U(t) and plot the solutions
(a) PROGRAM:
clc;
clear all;
close all;
syms i(t);
V=20;
R1=9;
L1=1;
C1=0.05;
Di=diff(i);
eqn1= diff(i,t,2)+(R1/L1)*diff(i,t)+(1/(L1*C1))* i ==0;
cond1=[i(0)==0, Di(0)==20];
soln1= dsolve(eqn1, cond1);
t=0:.005:5;
s1=subs(soln1); plot(t,s1,'r',
'linewidth',2);
title('Current Transient through RlC circuit');
xlabel('time');
ylabel('Current through the circuit');
OUTPUT:
(b) PROGRAM:
clc;
clear all;
close all;
syms i(t);
V=20*exp(-t);
R1=9;
L1=1; C1=0.05;
Di=diff(i);
eqn1= diff(i,t,2)+(R1/L1)*diff(i,t)+(1/(L1*C1))* i ==(1/L1)*diff(V,t);
cond1=[i(0)==0, Di(0)==20];
soln1= dsolve(eqn1, cond1);
t=0:.005:5;
s1=subs(soln1); plot(t,s1,'r',
'linewidth',2);
title('Current Transient through RlC circuit');
xlabel('time');
ylabel('Current through the circuit');
OUTPUT:
EXP NO: 6 DATE:
OBJECTIVE:
● To visualize the data in different ways
1. Plot a cosine signal added w ith random noise using scatter plot
PROGRAM:
x = 0:0.01:10;
len=length(x);
y = cos(x) + rand(1,len); sz
= 25;
c = 0:0.01:10;
scatter(x,y,sz,c,'filled')
title('Scatter plot: Cosine signal added with a random noise')
OUTPUT:
OUTPUT:
3.Plot the bar plot of the data y= [75 91 105 123.5 131 150 179 203 226 249 281.5] having
values on the x axis as [1900:10:2000].
PROGRAM:
x = 1900:10:2000;
y = [75 91 105 123.5 131 150 179 203 226 249 281.5];
bar(x,y)
OUTPUT:
4. Plot the bar plot of the matrix
(112 6
22 32
9
OUTPUT:
OUTPUT:
x=
0.3191 0.9861 0.7182 0.4132 0.0986
y=
0.7346 0.6373 0.0738 0.1205 0.9816
6. Plot the histogram of some random data, w ith the number of bins specified
PROGRAM:
x = randn(1000,1);
nbins = 25;
h = histogram(x,nbins)
OUTPUT:
h=
Histogram with properties:
Data: [1000×1 double]
Values: [1 4 14 13 26 34 48 66 76 86 91 109 103 77 79 59 40 28 25 10 3 5 1 1 1]
NumBins: 25
BinEdges: [-2.8000 -2.5500 -2.3000 -2.0500 -1.8000 -1.5500 -1.3000 -1.0500 -
0.8000 -
0.5500 -0.3000 -0.0500 0.2000 0.4500 0.7000 0.9500 1.2000 1.4500 1.7000 1.9500 2.2000
2.4500
2.7000 2.9500 3.2000 3.4500]
BinWidth: 0.2500
BinLimits: [-2.8000 3.4500]
Normalization:
'count' FaceColor:
'auto' EdgeColor: [0
0 0]
PLOT:
7. Plot the data [57, 57, 57, 58, 63, 66, 66, 67, 67, 68, 69, 70, 70, 70, 70, 72, 73, 75, 75, 76,
76,
78,79, 81] using box plot.
PROGRAM:
x=[57, 57, 57, 58, 63, 66, 66, 67, 67, 68, 69, 70, 70, 70, 70, 72, 73, 75, 75, 76, 76,
78, 79, 81];
boxplot(x)
OUTPUT:
8. Define ‘t’ as an array (-10, 10) w ith an increment of 0.01. Plot
(i)cos(t)
(ii) cost cos5t + cos5t
On the same graph. Create legends in plots
PROGRAM:
clc;
clear all;
close all;
t=-10:0.01:10;
y=cos(t);
plot(t,y,'k','linewidth',2)
hold on;
y=(cos(t).*cos(5*t))+cos(5*t);
plot(t,y,'r', 'linewidth',2)
hold on;
legend('cos(t)','cost cos5t + cos5t');
OUTPUT:
EXP NO: 7 DATE:
OBJECTIVE:
Simple Data Analysis
1. To plot a find mean and variance of random signal and Plot its histogram w ith
an appropriate bin size.
PROGRAM:
clc
clear all
close all
t=0:1:99;
x=randi(10,100);
subplot(4,1,1) plot(t,x)
title('Random
signal')
mu=mean(x);
stan=std(x);
subplot(4,1,2)
plot(t,mu)
title('Mean of Random signal')
subplot(4,1,3)
plot(t,stan)
title('Standard deviation Random signal')
subplot(4,1,4)
hist(x)
title('Histogram of Random signal')
OUTPUT:
EXP NO: 8 DATE:
OBJECTIVE:
To study the coin tossing problem and level crossing problem
OUTPUT:
OUTPUT:
Number of points above
threshold= 85
Number of points below
threshold 15
TEXTBOOK EXERCISE
1. silicon sample is doped w ith 1017 arsanic atoms per sq.cm. What is the equavalent
hole concentration p0 at 300k. w hat is the relation betw een Ef and Ei .
Program:
%At room temperature 300k, KT/q = 26mV
KT = 26;
ni = 1.5*10^(10);%for silicon n0
= 10^17;
nd = n0;
p0 = (ni*ni)/n0*10^(-3);
%distance between Ef and Ei
%Ef - Ei = x
x = -KT*log(ni/n0);
x*10^(-3)
solution:
x = 0.4085