Sahil Ecb Isp

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

Experiment 1(a)

To compute basic mathematical quantities and perform operation on arrays using


MATLAB.

a. Solve π(1/3) -1 and then compute 2πrh with h=9.

>> h=9;

r = (pi)^(1/3)-1

r = 0.4646

>>2*(pi)*r*h

ans = 26.2721

b. Solve loge3

>>log(exp(3))

ans = 3

c. Solve log10e3

>>log10(exp(3))

ans = 1.3029

d. Solve log(e(3^2) -1)

>>log(exp(3^2)-1)

ans = 8.9999

e.Solve log(e(3^2-1) )

>>log(exp((3^2)-1))

ans =8
f. Solve sin(π/6)2+cos(π/6)2

>> r = 0.4646 (sin(pi/6))^2+(cos(pi/6))^2

ans = 1

g. Solve eπ/2i

>>exp((pi)/(2*i))

ans = 0.0000 - 1.0000i


Experiment 1(b)
To create arrays and perform arithmetic operations on them.

a. The equation of straight line is y=mx+c where m and c are constant. Compute the y
coordinates of a line with m= 4 and intercept c = -1 at the following x coordinates : 0 to 15.

>>m= 4;

>> c= -1;

>> x= 0:15;

>> y=(m*x)+c

y = -1 3 7 11 15 19 23 27 31 35 39 43 47 51 55 59

b. Create a column vector for A with the values 0, pi/4, pi/2, 3pi/4, pi, 5pi/4. Take r= 2 and
compute the column vectors x= rcos(A) and y= rsin(A) and verify the equation of a circle
x^2 + y^2=r^2.

>> r=2;

>> A=[0;pi/4;pi/2;(3*(pi))/4;pi;(5*(pi))/4]

A=

0.7854

1.5708

2.3562

3.1416

3.9270

>> x=r*cos(A)

x=

2.0000
1.4142

0.0000

-1.4142

-2.0000

-1.4142

>> y=r*sin(A)

y=

1.4142

2.0000

1.4142

0.0000

-1.4142

>> (x.^2)+(y.^2)

ans =

>> r^2

ans = 4
c. Create a vector x of 11 elements from 0 to 10. Take r= 0.5 nd verify the geometric series
1+r+r^2+r^3+......r^n= 1/(1-r). Repeat the procedures taking n from 0 to 50 and then 0 to
100.

>> n= 0:10;

>> r= 0.5;

LHS

>> sum(r.^n)

ans = 1.9990

RHS

>> 1/(1-r)

ans = 2

LHS=RHS, Hence Verified.

>> n= 0:50;

LHS

>> sum(r.^n)

ans = 2.0000

RHS
>> 1/(1-r)

ans = 2

LHS=RHS, Hence Verified.

>> n=0:100;

LHS

>> sum(r.^n)

ans = 2

RHS

>> 1/(1-r)

ans = 2

LHS=RHS, Hence Verified.

Experiment 2
To generate 2D and 3D using script and function files.

a. Plot y=sinx , x from 0 to π. Take 100 linearly spaced points in given interval.
x = linspace(0,2*pi);
y = sin(x);
plot(x,y)
xlabel('x')
ylabel('y = sinx')
title('this plot is created by roll no. ')

b. Plot y=e(-0.4x) * sin(x), x is from 0 to 4π taking 10,50,100 points in the interval.


x=linspace(0,4*pi,10);
y=exp(-0.4*x).*sin(x);
subplot(3,1,1)
plot(x,y)
xlabel('x')
ylabel('y')
title('This plot is created by roll no ')
x=linspace(0,4*pi,50);
y=exp(-0.4*x).*sin(x);
subplot(3,1,2)
plot(x,y)
xlabel('x')
ylabel('y')
title('This plot is created by roll no ')
x=linspace(0,4*pi,100);
y=exp(-0.4*x).*sin(x);
subplot(3,1,3)
plot(x,y)
xlabel('x')
ylabel('y')
title('This plot is created by roll no ')

Output:

c. Plot y= cosx and z=1-x2/2+x4/24, where x lies between 0 to π.


x=linspace(0,pi);
y=cos(x);
z = 1-(x.^2/2)+(x.^4/24);
plot(x,y,x,z)
legend('y = cos(x)','z = 1-(x.^2/2)+(x.^4/24)')
xlabel('x')
ylabel('y and z')
title('This plot is created by roll no ')

Output:
d. Write a script file to draw a unit circle.
theta=linspace(0,2*pi,50);
x=cos(theta);
y=sin(theta);
plot(x,y)
axis('equal')
xlabel('x')
ylabel('y')
title('circle')

Output:
e. Write a function to compute the factorial of any integer r.
factorial[fact]=factorial(n)
fact=1;
for i=n:-1:1
fact=fact*i
end

Output:

>> factorial(5)

ans = 120
Experiment - 3

To create MATALAB Code for the generation of Unit step, Unit impulse, Exponential and
Ramp signal in continous and discrete domain.

%CONTINOUS UNIT STEP FUNCTION


t=linspace(-5,5);
x= (t>=0);
subplot(5,2,1)
plot(t,x)
xlabel('t')
ylabel('x(t)')
title('continous unit step signal created by Roll No. ')

%DISCRETE UNIT STEP FUNCTION


n=-5:5;
x= (n>=0);
subplot(5,2,2)
stem(n,x)
xlabel('n')
ylabel('x(n)')
title('discrete unit step signal created by Roll No. ')

%CONTINOUS UNIT IMPULSE FUNCTION


t=(-5:0.01:5);
x= t==0;
subplot(5,2,3)
plot(t,x)
xlabel('t')
ylabel('x(t)')
title('continous impulse signal created by Roll No. ')

%DISCRETE UNIT IMPULSE FUNCTION


n=-5:5;
x= n==0;
subplot(5,2,4)
stem(n,x)
xlabel('n')
ylabel('x(n)')
title('discrete impulse signal created by Roll No. ')

%CONTINOUS EXPONENTIAL RISING SIGNAL FUNCTION


t=linspace(-5,5);
x= exp(t);
subplot(5,2,5)
plot(t,x)
xlabel('t')
ylabel('x=exp(t)')
title('continous exponential rising signal created by Roll No. ')

%CONTINOUS EXPONENTIAL DECAYING SIGNAL FUNCTION


t=linspace(-5,5);
x= exp(-t);
subplot(5,2,6)
plot(t,x)
xlabel('t')
ylabel('x=exp(-t)')
title('continous exponential decaying signal created by Roll No. ')

%DISCRETE EXPONENTIAL RISING SIGNAL FUNCTION FOR a>1


n=-10:10;
a=1.5;
x=a.^n;
subplot(5,2,7)
stem(n,x)
xlabel('n')
ylabel('x(n)')
title('discrete exponential signal for a>1 created by Roll No. ')

%CONTINOUS RAMP SIGNAL


t=linspace(-5,5);
x=t.*(t>=0);
subplot(5,2,8)
plot(t,x)
xlabel('t')
ylabel('x(t)')
title('continous ramp signal created by Roll No. ')

%DISCRETE RAMP SIGNAL


n=-10:10;
x= n.*(n>=0);
subplot(5,2,9)
stem(n,x)
xlabel('n')
ylabel('x(n)')
title('discrete ramp signal created by Roll No. ')
Experiment 4

AIM:- To create MATLAB code for performing operations on continous time signals like
addition, multiplication, shifting and scaling:-

t=linspace(-10,10);
x1= (t>=0);
x2= (t>=-2);

%Addition of two signals


x=x1+x2;
subplot(4,1,1)
plot(t,x)
xlabel('t')
ylabel('x(t)')
title('Addition of two continous signals created by Roll No. ')

%Multiplication of two signals


y=x1.*x2;
subplot(4,1,2)
plot(t,y)
xlabel('t')
ylabel('y(t)')
title('Multiplication of two continous signals created by Roll No. ')

%Shifting of signals
z=t+5;
subplot(4,1,3)
plot(z,x1)
xlabel('t')
ylabel('x1(z)')
title('Shifting of signals created by Roll No. ')

%Scaling of signals
z1=2.*t+5;
subplot(4,1,4)
plot(z1,x1)
xlabel('t')
ylabel('x1(z1)')
title('Scaling of signals created by Roll No. ')
OUTPUT:-
Experiment 5

AIM:- To Compute Fourier Transform and Inverse Fourier Transform of the signal in
MATLAB :-

syms t x
f= exp(-t^2-x^2);
z= fourier(f)
p=ifourier(z)

OUTPUT:-

z=

pi^(1/2)*exp(- t^2 - w^2/4)

p=

exp(- t^2 - x^2)


Experiment-6

AIM:- To compute Convolution and Correlation between continous-time signal :-

t=linspace(0,2*pi);
x=cos(t);
y=sin(t);
z=conv(x,y);
w=0:length(z)-1;
subplot(1,2,1)
plot(w,z)
xlabel('w')
ylabel('z')
title('Convolved continous signal created by Roll No. ')

s=xcorr(x,y);
p=0:length(s)-1;
subplot(1,2,2)
plot(p,s)
xlabel('p')
ylabel('s')
title('Discrete correlation signal created by Roll No. ')

OUTPUT:-
EXPERIMENT 7

AIM: To generate random sequences for the following distribution


and plot probability density function :-
Rayleigh distribution

Uniform distribution

Normal or Gaussian distribution

r = raylrnd(1:5);
u = unifrnd(1,2:5);
n = normrnd(1,3:6);
x = [-2:0.0001:2.5];
p = raylpdf(x,0.5);
subplot(3,1,1)
plot(x,p)
xlabel('x')
ylabel('p')
title('pdf for Rayleigh distribution created by Roll No. ')
p = unifpdf(x,1,2);
subplot(3,1,2)
plot(x,p)
xlabel('x')
ylabel('p')
title('pdf for Uniform distribution created by Roll No. ')
p = normpdf(x,0.5,1);
subplot(3,1,3)
plot(x,p)
xlabel('x')
ylabel('p')
title('pdf for Normal or Gaussian distribution created by Roll No. ')
OUTPUT:-
EXPERIMENT 8
AIM:- To perform basic mathematical opertions on matrices using Python:-

(A)
import numpy as np
x = np.array([[1,2],[3,4]])
y = np.array([[7,8],[9,10]])
print('Addition of two matrices')
print(np.add(x,y))

OUTPUT:-
Addition of two matrices :
[[ 8 10]
[12 14]]

(B)
print('Subtraction of two matrices :')
print(np.subtract(x,y))

OUTPUT:-
Subtraction of two matrices :
[[-6 -6]
[-6 -6]]

(C)
print('Multiplication of two matrices :')
print(np.multiply(x,y))
OUTPUT:-
Multiplication of two matrices :
[[ 7 16]
[27 40]]

(D)
print('Division of two matrices :')
print(np.divide(x,y))

OUTPUT:-
Division of two matrices :
[[0.14285714 0.25 ]
[0.33333333 0.4 ]]

(E)
print('Dot product of two matrices :')
print(np.dot(x,y))

OUTPUT:-
Dot product of two matrices :
[[25 28]
[57 64]]

(F)
print('Square root of matrix :')
print(np.sqrt(x))
OUTPUT:-
Square root of matrix :
[[1. 1.41421356]
[1.73205081 2. ]]

(G)
print('Summation of matrix :')
print(np.sum(y))

OUTPUT:-
Summation of matrix :
34

(H)
print('The column wise Summation :')
print(np.sum(y,axis=0))

OUTPUT:-
The column wise Summation :
[16 18]

(I)
print('The row wise Summation :')
print(np.sum(y,axis=1))

OUTPUT:-
The row wise Summation :
[15 19]

(J)
print('The Transpose of matrix :')
print(x.T)

OUTPUT:-

The Transpose of matrix :


[[1 3]
[2 4]]
EXPERIMENT 9
AIM:-To create graphs in Python using the matplotlib library:-

(A)
import matplotlib.pyplot as plt
plt.plot([1,2,3,4])
plt.ylabel('some numbers ')
plt.show()

OUTPUT:-
(B)
import matplotlib.pyplot as plt
plt.plot([1,2,3,4],[1,4,9,16],'ro')
plt.axis([0,6,0,20])
plt.show()

OUTPUT:-
(C)
import matplotlib.pyplot as plt

import numpy as np

t = np.arange(0.,5.,0.2)

plt.plot(t,t,'r--',t,t**2,'bs',t,t**3,'g^')

plt.show()

OUTPUT:-
(D)
import matplotlib.pyplot as plt
import numpy as np
names = ['group_a','group_b','group_c']
values = [1,10,100]
plt.figure(figsize=(9,3))
plt.subplot(131)
plt.bar(names,values)
plt.subplot(132)
plt.scatter(names,values)
plt.subplot(133)
plt.plot(names,values)
plt.suptitle('Categorical Plotting')
plt.show()

OUTPUT:-

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy