Sei sulla pagina 1di 26

ESS ASSIGNMENT

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

3. Do the following operation using MATLAB.

(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

ANS: Columns 1 through 5

3.0000 3.2500 3.5000 3.7500 4.0000

Columns 6 through 10

4.2500 4.5000 4.7500 5.0000 5.2500

Columns 11 through 15

5.5000 5.7500 6.0000 6.2500 6.5000

Columns 16 through 20

6.7500 7.0000 7.2500 7.5000 7.7500

Columns 21 through 25

8.0000 8.2500 8.5000 8.7500 9.0000

Columns 26 through 30

9.2500 9.5000 9.7500 10.0000 10.2500

Columns 31 through 33

10.5000 10.7500 11.0000

(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

-5.0000 -4.4737 -3.9474 -3.4211 -2.8947

Columns 6 through 10

-2.3684 -1.8421 -1.3158 -0.7895 -0.2632

Columns 11 through 15

0.2632 0.7895 1.3158 1.8421 2.3684

Columns 16 through 20

2.8947 3.4211 3.9474 4.4737 5.0000

(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

0.0100 0.0110 0.0121 0.0133

Columns 5 through 8

0.0146 0.0160 0.0176 0.0193

Columns 9 through 12

0.0212 0.0233 0.0256 0.0281

Columns 13 through 16

0.0309 0.0339 0.0373 0.0409

Columns 17 through 20

0.0450 0.0494 0.0543 0.0596

Columns 21 through 24

0.0655 0.0720 0.0791 0.0869

Columns 25 through 28

0.0954 0.1048 0.1151 0.1265

Columns 29 through 32

0.1389 0.1526 0.1677 0.1842

Columns 33 through 36

0.2024 0.2223 0.2442 0.2683

Columns 37 through 40

0.2947 0.3237 0.3556 0.3907

Columns 41 through 44

0.4292 0.4715 0.5179 0.5690

Columns 45 through 48

0.6251 0.6866 0.7543 0.8286

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.

Ans: str1=input('Enter name1','s')

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}

output Enter name1 madhu

str1 = madhu

Enter name2 nagaiah

str2 = nagaiah

n1 = 5

n2 = 7

str2 = nagai

ans =

' madhu' ' nagai'

5. What will be the output of the following commands

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

A=[8 1 6;3 5 7;4 9 2]

ANS:

output A =

8 1 6

3 5 7

4 9 2

B=A^-1

ANS:

B=

0.1472 -0.1444 0.0639

-0.0611 0.0222 0.1056

-0.0194 0.1889 -0.1028

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 =

8.0000 1.0000 6.0000

3.0000 5.0000 7.0000

4.0000 9.0000 2.0000

E=B/C

ANS:

output E =
ESS ASSIGNMENT

0.1472 -0.1444 0.0639

-0.0611 0.0222 0.1056

-0.0194 0.1889 -0.1028

7. What will be the MATLAB output for the following expressions

[1 0 7]>=[1+2*i 5*i 7+7*i]

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

e=[1 2;3 4];


ESS ASSIGNMENT

ANS:

output e =

1 2

3 4

f=[2 3;4 5];

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

9. What is the output generated by following MATLAB commands?

x= [1 2 3;4 5 6];

Y=exp(x)

ANS:

output y =

2.7183 7.3891 20.0855

54.5982 148.4132 403.4288

%q b

x=[-pi:- pi/2:pi];

ANS:

output X =

-3.1416 -1.5708 0 1.5708 3.1416

y=sin(x). ^2+cos(x).^2

ANS: Output y =

1.0000 1.0000 1.0000

1.0000 1.0000 1.0000


ESS ASSIGNMENT

10. Given the matrices

a= [-3, 11;5,- 7];

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

11. Prove that A3 - 4A2 - 3A + 11I=0

Where A=[1 3 2; 2 0 -1; 1 3 2] and I is unity matrix and 0 is null matrix.

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

12.Given a matrix A=[1 3 5 7; 2 4 6 8; 5 1 7 9; 9 1 5 7]

Create the following sub matrices from the elements of A

(a) Matrix made of only odd columns of A


(b) Ans a=[1 3 5 7;2 4 6 8;5 1 7 9;9 1 5 7]
(c) p=[a(:,1) a(:,3)]

output p =

1 5

2 6

5 7

9 5

(b) Matrix made of only even rows of A

Ans q=[a(2,:) a(4,:)]

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

Ans r=[a(1,1) a(1,3);a(3,1) a(3,3)]

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 =

13. Matrix A is given as A= [11 12 13 14; 21 22 23 24; 31 32 33 34; 41 42 43 44].Perform the


following operations on matrix A

(a) Interchange the first and fourth rows.

(b) Interchange the second and third columns.

(c) Interchange the second row with second column

(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

(f) What will be the result of following operation ?

Explain

P=A ( [1 3 4 2], [3 1 4 2] )

Ans

: a=[11 12 13 14;21 22 23 24;31 32 33 34;41 42 43 44]

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

d(2,:)=d(:,2) d(:,2)=p g=a %d

g([1,3],:)=0 g(:,[1,3])=0 a(:,[3 1 2 4]) %e h=a([1 3 4 2],[3 1 4 2]) %f

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"

Q.1 Let x = -6+8j

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

Q.3 If =1, and r=5, then convert Polar to Cartesian coordinate.

ans:

theta=1

%polar to cartisian r=5

[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

ans: a=3.2 ,b=4.6

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!

ans: x=1.5 s1=1-((x^2)/factorial(2))+((x^4)/factorial(4))((x^6)/factorial(6))+((x^8)/factorial(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

f1=a*b/(c*d)+a*b and f2=a/(b*c)-d/a

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

Write a program to calculate the frequency for

different values of c varying from0.1 to 1in steps of 0.1

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=

0.1000 1.1000 2.1000 3.1000 4.1000 5.1000 6.1000 7.1000 8.1000

f = 864.4118

Q.10 Evaluate the following trigonometric functions for theta 30 ,120 ,210 and300

i. sin (theta)

ii. cos (theta)

iii. tan (theta)

iv. cot (theta)

ans: o1=pi/6

o2=(2*pi)/3

o3=(7*pi)/6

o4=(5*pi)/3

s1=sin(o1) , s2=sin(o2) , s3=sin(o3), s4=sin(o4), c1=cos(o1), c2=cos(o2), c3=cos(o3),


c4=cos(o4) t1=tan(o1), t2=tan(o2), t3=tan(o3), t4=tan(o4)

co1=cot(01) co2=cot(02) co3=cot(03) co4=cot(04)

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

Q.11 Evaluate the following trigonometric functions for theta=3,5and 8

. i. sinh (theta)

ii. cosh (theta)

iii. tanh (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 .^

a=[1 2 3;4 5 6;7 8 9]


ANS:
a=1 2 3
4 5 6
7 8 9
b=sqrt(mean(a^2))
ANS:
b =8.1240 9.0000 9.7980
(b) Make a graph of y = sin(x), for x on the interval x=0, to x = 10
x=0:0.1:10
y=sin(x)
plot(x,y)
ANS:

Q.2. Solve the set of linear algebraic equations:


3a + 7b -1.5c = 9 ; 3.2b + c = 2 ; (1/9)a -12b = 0
ANS:
syms a b c
eq1 = 3*a+7*b-1.5*c==9
eq2 = 3.2*b+c==2
eq3 = (1/9)*a-12*b==0
[A,B]=equationsToMatrix([eq1 ,eq2, eq3],[a, b, c])
X=linsolve(A,B)

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.4. Find the magnitude and angle of z = 5-3j


ANS:
z=5-3*j
a=abs(z)
a = 5.8310
b=angle(z)
b = -0.5404

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.6. Find the roots of A= 5s2+3s+2


ANS:
b=[5 3 2]
p=roots(b)
p = -0.3000 + 0.5568i
-0.3000 - 0.5568i

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

0.6901 + 0.0000i -0.2890 - 0.4199i -0.2890 + 0.4199i


ESS ASSIGNMENT

0.4241 + 0.0000i 0.6590 + 0.0000i 0.6590 + 0.0000i

E= 4.3153 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i

0.0000 + 0.0000i -2.6576 + 5.1987i 0.0000 + 0.0000i

0.0000 + 0.0000i 0.0000 + 0.0000i -2.6576 - 5.1987i

Potrebbero piacerti anche