Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
B.Madhu Naik
2016UEE1328
BATCH :E2
1.Use MATLAB to make the following calculations with values x=5 and y=2. Verify the results
with a calculator.
x=5; y=2;
U=(3*x)/(2*y)
ANS: U =3.7500
%q b
P=3/2*(x*y)
ANS: P =15
%q c
W=x*y^3/(x-y)
ANS: W =13.3333
%q d
P=x^3/(x^2+y^2+1)
ANS: P = 4.1667
%q e
Q=x*sin(y)*y*sin(x/5)
ANS: Q =7.6515
2. Evaluate (ex + e -x )/2 for x=2 using MATLAB. Enter the value of x before you write expression
x=2;
Y=(exp(x)+exp(-x))/2
ANS: Y =3.7622
(a) Create a vector y having a regular spacing of 0.25 between 3 and 11, using the colon notation (:)
and the using linspace command.
y=3:0.25:11
ESS ASSIGNMENT
Columns 6 through 10
Columns 11 through 15
Columns 16 through 20
Columns 21 through 25
Columns 26 through 30
Columns 31 through 33
(b) Create a vector z having 20 regularly spaced values starting at -5 and ending at -5, using the colon
notation (:) and linspace command.
Ans c=linspace(-5,5,20)
ANS: output c =
Columns 1 through 5
Columns 6 through 10
Columns 11 through 15
Columns 16 through 20
(c) Create a vector u having 50 logarithmically equally spaced values starting at 10 and ending at
1000
u=logspace(1,3,50)
ESS ASSIGNMENT
ANS: output d =
1.0e+03 *
Columns 1 through 4
Columns 5 through 8
Columns 9 through 12
Columns 13 through 16
Columns 17 through 20
Columns 21 through 24
Columns 25 through 28
Columns 29 through 32
Columns 33 through 36
Columns 37 through 40
Columns 41 through 44
Columns 45 through 48
Columns 49 through 50
0.9103 1.0000
ESS ASSIGNMENT
. 4. Write a MATLAB code to take the names of two students, truncate them to the length of one with
lesser number of characters, and then compare them to decide which one comes first in the alphabetic
list.
str2=input('Enter name2','s')
n1=length(str1)
n2=length(str2)
if n1>n2
str1=str1(1:n2)
else
str2=str2(1:n1)
end sort({str1,str2}
str1 = madhu
str2 = nagaiah
n1 = 5
n2 = 7
str2 = nagai
ans =
A=[1,2;3,4]
Output A =
1 2
3 4
B= [A 2*A]
ESS ASSIGNMENT
Output B =
1 2 2 4
3 4 6 8
%qb
A(1,:)
ANS: output A=
1 2
%qc
B(:,2)
ANS: output B=
%qd
E=[A,B]
ANS:
output E =
3 4 1 2 2 4
1 2 3 4 6 8
%qf
A([1,2],:)=A([2,1],:)
ANS: output A =
1 2
3 4
6. Consider A=[8 1 6; 3 5 7; 4 9 2and B=inv(A), what will be the output of following commands?
(a) C=A*B
ESS ASSIGNMENT
ANS:
output A =
8 1 6
3 5 7
4 9 2
B=A^-1
ANS:
B=
C=A*B
ANS:
C=
1.0000 0 -0.0000
-0.0000 1.0000 0
0.0000 0 1.0000
D=C/B
ANS:
output D =
E=B/C
ANS:
output E =
ESS ASSIGNMENT
ANS=
1 1 1
(1+10*i)<(2+i)
output
ANS =
abs(1+10i)>abs(2+i)
output
ANS =
(d) 'raman'<='raghu'
ANS
output =
1 1 0 1 1
(e) 'Gopal'=='Gopal'
Output
ANS =
1 1 1 1 1
8. Assume matrices
ANS:
output e =
1 2
3 4
f=
2 3
4 5
%% Q
x=e*f
ANS:
x=
10 13
22 29
g=e.*f
ANS:
output y =
2 6
12 20
h=e^3
ANS:
h=
37 54
81 118
j=e.*3
ANS:
output j =
ESS ASSIGNMENT
1 8
27 64
k=e./f
ANS:
output k =
0.5000 0.6667
0.7500 0.8000
l=e.^f
ANS:
output l =
1 8
81 1024
x= [1 2 3;4 5 6];
Y=exp(x)
ANS:
output y =
%q b
x=[-pi:- pi/2:pi];
ANS:
output X =
y=sin(x). ^2+cos(x).^2
ANS: Output y =
ANS:
Output a =
-3 11
5 -7
b=[2,15;18,-5];
ANS: b =
2 15
18 -5
c= [1,10;9,12];
ANS: c =
1 10
9 12
d=transpose(a^-1)
ANS: d =
0.2059 0.1471
0.3235 0.0882
e= (transpose(a))^-1
ANS: e =
0.2059 0.1471
0.3235 0.0882
f=(a*b*c)^-1
ANS: f =
-0.0002 0.0010
0.0012 0.0010
g=c^-1*b^- 1*a^-1
ANS: h =
ESS ASSIGNMENT
-0.0002 0.0010
0.0012 0.0010
a= [1 3 2;2 0 -1;1 3 2]
i= [1 0 0 ;0 1 0;0 0 1]
P=a*a*a-4.*a^2- 3.*a+11*i
ANS: output p =
0 0 0
0 0 0
0 0 0
output p =
1 5
2 6
5 7
9 5
output q =
2 4 6 8 9 1 5 7
Matrix made of all those elements of A, which belong neither to the even columns and nor to the even
rows of the original matrix
ESS ASSIGNMENT
output r =
1 5
5 7
(d) Write a MATLAB command to eliminate the last row and last column of a given matrix
regardless of its size.
(e) Ans a(4,:)=[] a(:,4)=[]
output a =
1 3 5 7
2 4 6 8
5 1 7 9
a=
1 3 5
2 4 6
5 1 7
(f) Write MATLAB commands to access the second last row and second last column of any given
matrix A, irrespective of its size.
(g) Ans s=a (:,3) s=a(3,:)
(h) f1=a(end-1,:) g1=a(:,end-1)
Output s =
s=
ESS ASSIGNMENT
5 1 7
f1 =
2 4 6
g1 =
(d) Reset all elements with odd row and column numbers to zero; rest of the elements must remain
unchanged.
(e) Rearrange all the columns of the matrix A with their order changed to the sequence:
3,1,4,2
Explain
P=A ( [1 3 4 2], [3 1 4 2] )
Ans
b=a([4,2,3,1],:)
%a
a([1,4],:)=a([4,1],:)
ESS ASSIGNMENT
c=a(:,[1 3 2 4])
%b a(:,[2,3])=a(:,[3,2])
d=a %c
a(1:2:end,:)=0 p=d(2,:)
%s1
a(:,1:2:end)=0
Output: a =
11 12 13 14
21 22 23 24
31 32 33 34
41 42 43 44
b=
41 42 43 44
21 22 23 24
31 32 33 34
11 12 13 14
c=
11 13 12 14
21 23 22 24
31 33 32 34
41 43 42 44
d=
11 12 13 14
21 22 23 24
31 32 33 34
ESS ASSIGNMENT
41 42 43 44
p=
21 22 23 24
d=
11 12 13 14
12 22 32 42
31 32 33 34
41 42 43 44
d=
11 21 13 14
12 22 32 42
31 23 33 34
41 24 43 44
g=
11 12 13 14
21 22 23 24
31 32 33 34
41 42 43 44
g=
0 0 0 0
21 22 23 24
0 0 0 0
41 42 43 44
g=0 0 0 0
0 22 0 24
0 0 0 0
0 42 0 44
ans =
ESS ASSIGNMENT
13 11 12 14
23 21 22 24
33 31 32 34
43 41 42 44
h=
13 11 14 12
33 31 34 32
43 41 44 42
23 21 24 22
"Sheet No.1B"
Find
i. Real component of x
ii. Real component of x
iii. Magnitude of x (use three different methods)
iv. Phase angle of x (two different methods)
v. Phase angle in degrees using direct command
ANS: x=-6+8j
a=real(x)
b=imag(x)
abs (x)
%magnitude1
d=sqrt(a^2+b^2)
%magnitude2 e= (a^2+b^2)^
%magnitude3
abs3=srt(x*conj(x))
f=angle(x)
%angle1
g=atan2(b,a)
%angle2
ESS ASSIGNMENT
h=rad2deg(g)
%angle in degree
x = -6.0000 + 8.0000i
a = -6
b=8
ANS =10
d =10
e =
-6.0000 + 8.0000i
a = -6
b=8
ans = 10
d = 10
e = 10
f = 2.2143
g = 2.2143
h = 126.8699
Q.2 If x= 1+1j Convert Cartesian co-ordinates of the complex no. x into polar coordinates.
ans: x=1+1*j
a=abs(x)
b=angle(x)
a1=real(x)
b1=imag(x)
[theta,rho]=cart2pol(a1,b1)
%cart to polar
x=
2 9 28 65
a=
ESS ASSIGNMENT
2 9 28 65
b=
0 0 0 0
a1 =
2 9 28 65
b1 =
0 0 0 0
theta =
0 0 0 0
rho =
2 9 28 65
ans:
theta=1
[x,y]=pol2cart(theta,r)
theta =
r=
x=
2.7015
y=
4.2074
Q. 4 Given two sides a=3.2 and b=4.6 of a triangle and angle =60 between these two sides, find the
length of the third side and area of triangle.
ESS ASSIGNMENT
theta=pi/3
area=.5*a*b*sin(pi/3)
side=sqrt(-2*a*b*cos(pi/3)+a^2+b^2)
a =3.2000 ,b =4.6000
theta =1.0472
area =6.3739
side = 4.0841
Q.5 Write the MATLAB statements to calculate the sum of the series s=1-(x^2)/2!+(x^4)/4!-
(X^6)/6!+(x^8)/8!
x =1.5000
s1 = 0.0708
Q.6 The values of a, b, c and d are -190.5*10-2, 14.6*103, 0.00056 and 456.28 respectively. Write a
program to evaluate the following statements
ans:
=-190.5*10^-2
b=14.6*10^3
c=0.00056
d=456.28
f1=(a*b)/(c*d)+a*b f2=a/(b*c)-d/a
a =-1.9050
b = 14600
c = 5.6000e-04
d = 456.2800
f1 = -1.3666e+05
f2 = 239.2841
ESS ASSIGNMENT
Q.7 Given the radius of a circle r-5cm, find circumference and its area.
ANS: r=5
area= pi*r*r
circumference =2*pi r = 5
area =78.5398
circumferance = 31.4159
Q.8 Given the base of the right angle triangle =5cm and the acute angle, =42 Find the length of its
perpendicular
ANS: base=5
acuteangle=(42*pi)/180
perpendicularlength=5*tan((42*pi)/180)
base = 5
acuteangle =
0.7330
Perpendicular length =
4.5020
Q.9 For an electrical circuit with an inductance L=0.01mH and resistance R=100ohms, the damped
natural frequency of oscillation is
f=(1/(l*c)-R^2/(4*c^3))^1/2
ANS: l=0.01*10^-3
r=100
k=0.1:9
f=sqrt((1/(l*(c+0.1))-r^2/(4*(c+0.1)^2)))
l = 1.0000e-05
r = 100
ESS ASSIGNMENT
k=
f = 864.4118
Q.10 Evaluate the following trigonometric functions for theta 30 ,120 ,210 and300
i. sin (theta)
ans: o1=pi/6
o2=(2*pi)/3
o3=(7*pi)/6
o4=(5*pi)/3
o1 = 0.5236
o2 = 2.0944
o3 =3.6652
o4 = 5.2360
s1 = 0.5000
s2 = 0.8660
s3 = -0.5000
s4 = -0.8660
c1 = 0.8660
c2 = -0.5000
c3 = -0.8660
c4 = 0.5000
t1 = 0.5774
ESS ASSIGNMENT
t2 = -1.7321
t3 = 0.5774
t4 = -1.7321
co1 = 0.6421
co2 = 0.4577
co3 = -7.0153
co4 = 0.8637
. i. sinh (theta)
ans: o1=3
o2=5
o3=8
sinh(o1)
sinh(o2)
sinh(o3)
cosh(o1)
cosh(o2)
cosh(o3)
tanh(o1)
tanh(o2)
tanh(o3)
o1 =3 o2 = 5 o3 =8
ANS= 10.0179 , ANS = 74.2032, ANS = 1.4905e+03, ANS= 10.0677 , ANS = 74.2099 ,
ANS = 1.4905e+03 , ANS = 0.9951 , ANS = 0.9999 , ANS =1.0000
SHEET NO:1
ESS ASSIGNMENT
Q.1
(a)Compute the root-mean-square (RMS) value of the vector by using the commands
sqrt(), mean(), and .^
X=
6480/1679
60/1679
3166/167
Q.3. Plot sin(x) and cos(x) over [0,2], on the same plot with different colours.
ANS:
ESS ASSIGNMENT
x=0:0.1:2*pi
y=sin(x)
y2=cos(x)
plot(x,y,x,y2)
Q.5. v = (5+j9)(7+j)
3j2
Find the real and imaginary part of a complex number,v.
ANS:
v=((5+j*9)*(7+j))/(3-j*2)
x=real(v)
x = -4.4615
y=imag(v)
y = 19.6923
Q.7. Find the value of the expression, y = e(a) sin(x) + 10y, for a = 5, x = 2, and y = 8.
ANS:
a=5
x=2
y=8
y=exp(-x)*sin(x)+10*sqrt(y)
ESS ASSIGNMENT
y= 8
Q.8. If R = 10 and the current is increased from 0 to 10 A with increments of 2A, write a
MATLAB program to find current, voltage and power dissipation.
ANS:
r=10
i=0:2:10
v=i*r
p=i.^2*r
v = 0 20 40 60 80 100
p= 0 40 160 360 640 1000
Q.9. Creates a 3x3 matrix, A in which the first row has elements 3, 9, 1, the second row has
elements 4, 8, 6, and the third row has elements 8, 2, 0. (a) Extract the third column of A
and store in B (b) extract the first and second rows in store in C (c) find the sum of first
two elements of third column of A and store in D.
ANS:
a= [3 9 1;4 8 6;8 2 0]
a=
3 9 1
4 8 6
8 2 0
b=[a(:,3)]
b= 1
6
0
c=[a(1:2,:)]
c= 3 9 1
4 8 6
d=[a(1,3)+a(2,3)]
d=7
Q.10. For the matrix A defined in above problem (a) Sort columns in descending order,(b) Sort
rows in descending order (c) Find Eigenvalues and Eigenvectors of A and store in E and
V respectively.
ANS:
a=[3 9 1;4 6 8;8 2 0]
(a)
p=sort(a,'descend')
p= 8 9 8
4 6 1
3 2 0
(b)
q=sortrows(a,-2)
q= 3 9 1
4 6 8
8 2 0
(c)
[V,E]=eig(a)
V= 0.5864 + 0.0000i -0.1467 + 0.5332i -0.1467 - 0.5332i