Sahil Ecb Isp
Sahil Ecb Isp
Sahil Ecb Isp
>> 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
>>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
ans = 1
g. Solve eπ/2i
>>exp((pi)/(2*i))
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
>> n= 0:50;
LHS
>> sum(r.^n)
ans = 2.0000
RHS
>> 1/(1-r)
ans = 2
>> n=0:100;
LHS
>> sum(r.^n)
ans = 2
RHS
>> 1/(1-r)
ans = 2
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. ')
Output:
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.
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);
%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=
p=
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
Uniform 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:-
(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:-