You are on page 1of 22

ARYA COLLEGE OF ENGINEERING

AND INFORMATION TECHNOLOGY

DEPARTMENT OF ELECTRICAL ENGINEERING

LAB - RECORD

V SEM

5EE4-24

SYSTEM PROGAMMING LAB

Submitted To Submitted By
Dr. Virendra Sharma Gajendra Teli
Department of Electrical 20EAREE021
Engineering B.Tech Third Year
Electrical Engineering
ASSIGNMENT NO: 1

Question – 1 calculate: -

A. 56 / (√2 3 + 14) + (14.82 + 5.52)

B. 206 1/3 + ((-4.4)3 + e6 / ln524)


Solution: - A. 56/ (sqrt (3) + 14) + (14.8^2 + 5.5^2)
Ans = 252.8496
B. 206^1/3 + ((-4.4) ^3 + exp (6) / log (524))
Ans = 47.9128
Question – 2 calculate: -

A. 16.52(8.4-√2 70) / 4.32 – 17.3

B. 24 (7.1/5 + 14/6.1 + √3 30 ) / (9/2.5)2 - (log (85))2

Solution - A. 16.5^2*(8.4 - sqrt (70))/4.3^2-17.3


Ans = -16.8082
B. 24*(7.1/5 + 14/6.1 + nthroot (30,3)/ (9/2.5) ^2 -(log (85)) ^2)
Ans = -378.7755
Question – 3 define the variable x as x =2.34, then evaluate;
A. 1.5x4 - 5 x3 + 16x2 + 8.7
B. (3x)2 / log (5 + 3x2 + 6x)
Solution: - A. x = 2.34;
A=1.5*x^4 - 5*x^3 + 16*x^2 + 8.7
A = 77.2184
B. x = 2.34;
B= (3*x) ^2 / log(5+3*x^2+6*x)
B = 13.8095
Question 4: - Two trigonometric identities are given by:
a. cos4x = 8(cosx)4 - 8(cosx)2 + 1

b. tan (x/2) = √2 (1−cosx )/(1+cosx )

Solution: - A. x = 12;

1
Taking L.H.S >> cos(4*x)
Ans = -0.6401
Taking R.H.S. >> 8*(cos(x)) ^4 - 8*(cos(x)) ^2 +1
Ans = -0.6401
L.H.S. = R.H.S. Hence proved
B. >> x = 12;
Taking L.H.S >> tan(x/2)
Ans = -0.2910
Taking R.H.S. >> sqrt((1-cos(x))/(1+cos(x)))
Ans = -0.2910
L.H.S = R.H.S hence Proved
Question 5: - Define the two variables: alpha = 5π/8, and beta = π/8. Using these variables;
show the following trigonometric identity is correct by calculating the values of the left and
right sides of the equation.
¿ α −β
Sinα + sin β = 2sin (α + β ¿ 2 ) cos ( )
2

Solution: - >> a = 5*pi/8; {here we considering a as alpha(α)}


>> b = pi/8; {here we considering b as beta(β)}
Taking L.H.S. >> sin(a) + sin (b)
Ans = 1.3066
Taking R.H.S >> 2*sin ((a + b)/2) *cos((a-b)/2)
Ans =1.3066
L.H.S = R.H.S Hence proved
Question 6: - create a row vector that has the following elements:

3,4.2,55,68/16,45,√3 110,cos 250 and 0.05.

Solution: - >> r = [3, 4.2, 55, 68/16, 45, nthroot (110,3), cos (25), 0.5]
r=
3.0000 4.2000 55.0000 4.2500 45.0000 4.7914 0.9912 0.5000
Question 7: - Define the variable x = 0.85, y = 0.25, and then use them to create a column
vector that has the following elements: y, yx, ln (y/x), y.x, and y+x.
Solution: ->> x = 0.85;
2
>> y = 0.25;
>> c = [y; y^x; log(y/x); y*x; y+x;]
c=
0.2500
0.3078
-1.2238
0.2125
1.1000
Question 8: - use a single command to create a row vector (assign it to a variable named b)
with 19 element such that
b = 1 2 3 4 5 6 7 8 9 10 9 8 7 6 5 4 3 2 1
Do not type the vector explicitly
Solution: - >> b = [1:1:10 9:-1:1]
b=
1 2 3 4 5 6 7 8 9 10 9 8 7 6 5 4 3 2 1

3
ASSIGNMET NO: 2

Question 1: - Create three row vectors:


a = [7 2 -3 1], b = [-3 10 1 7 -2], c = [1 0 4 -6 5]
A. Use the three vectors in a MATLAB comment to create a 3*3 matrix such that the first,
second and third rows consist of the first three elements of the vectors a, b, and c
respectively.
B. Use the three vectors in a MATLAB command to create a matrix such that the first,
second, and third column consist of the first three elements of the vectors a, b, and c
respectively.
Solution: - A. >>a= [7 2 -3 1 0];
>>b= [-3 10 1 7 -2];
>>c= [1 0 4 -6 5];
% -----find A
>>A= [ a (1:3); b (1:3); c (1:3)]
A=
7 2 -3
-3 10 1
1 0 4
B. B = [a (3:5); b (3:5); c (3:5)]
B=
-3 1 0
1 7 -2
4 -6 5
Question 2: -Create the following matrix E.
0 0 0 0 2 2 2
E = 0.7 0.6 0.5 0.4 0.3 0.2 0.1
2 4 6 8 10 12 14
22 19 16 13 10 7 4
A. Create 2*5 matrix F from the second and fourth rows, and the third through the seventh
column of matrix E.

4
B. Creates a matrix G from all rows and the third through fifth columns of matrix E.
Solution: -
>>E= [0 0 0 0 2 2 2; 0.7 0.6 0.5 0.4 0.3 0.2 0.2; 2 4 6 8 10 12 14; 22 19 16 13 10 7 4]
E=
0 0 0 0 2.0000 2.0000 2.0000
0.7000 0.6000 0.5000 0.4000 0.3000 0.2000 0.2000
2.0000 4.0000 6.0000 8.0000 10.0000 12.0000 14.0000
22.0000 19.0000 16.0000 13.0000 10.0000 7.0000 4.0000

>> f = E ([2 4], [3:7])


A. f =
0.5000 0.4000 0.3000 0.2000 0.2000
16.0000 13.0000 10.0000 7.0000 4.0000

B. G=E ([1:4], [3:5])


G=
0 0 2.0000
0.5000 0.4000 0.3000
6.0000 8.0000 10.0000
16.0000 13.0000 10.0000
Question 3: - the following matrix is defined as MATLAB.
33 21 9 14 30
30 18 6 18 34
N=
27 15 6 22 38
24 12 10 26 42
By hand (pencil and paper) Write what will be displayed if the following commands are
executed by MATLAB. Check your answer by executing the commands with MATLAB.
a. A = [N (1,1:4)’, N (2,2:5)’]
b. B = [N (:,3)’N(3,:)]
c. C (3:4, 5:6) = N (2:3, 4:5)
Solution: -

5
>>N=[33 21 9 14 30; 30 18 6 18 34; 27 15 6 22 38; 24 12 10 26 41]
N=
33 21 9 14 30
30 18 6 18 34
27 15 6 22 38
24 12 10 26 41
a. >>A=[N(1,1:4)',N(2,2:5)']
A=
33 18
21 6
9 18
14 34
b. >>B= [N (: ,3)', N (3, :)]
B=
9 6 6 10 27 15 6 22 38
C. >>C (3:4,5:6) =N (2:3,4:5)
C=
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 18 34
0 0 0 0 22 38
Question 4: - Using zeros, ones and eye commands, create the following arrays:
1 1 1 1 1 1
1 0 0 1 1
1 1 1 1 1 1
(a) (b) 0 1 0 1 1 (c)
0 0 0 0 0 0
0 0 1 1 1
0 0 1 1 1 1
Solution: - (a). >>a= [ones (2:2), zeros (2:2)]'
a=
1 1
1 1

6
0 0
0 0
(b). >>b=[eye(3,3),ones(3,3)]
b=
1 0 0 1 1 1
0 1 0 1 1 1
0 0 1 1 1 1
(c). >>c=[ones(2,4);zeros(1,4);ones(1,4)]
c=
1 1 1 1
1 1 1 1
0 0 0 0
1 1 1 1
Question 5: - Create a Matrix A in which the elements are 1. Then reassign A to itself
(several times) such that A will become.
1 1 0 0 1 1 0
1 1 0 0 1 1 0
0 0 1 1 0 0 1
0 0 1 1 0 0 1
Solution: - >>A=ones(4,8)
A=
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1

>>A(1:2,3:4)=zeros(2,2)
A=
1 1 0 0 1 1 1 1
1 1 0 0 1 1 1 1
1 1 1 1 1 1 1 1

7
1 1 1 1 1 1 1 1

>>A(1:2,7:8)=zeros(2,2)
A=
1 1 0 0 1 1 0 0
1 1 0 0 1 1 0 0
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
>>A(3:4,1:2)=zeros(2,2)
A=
1 1 0 0 1 1 0 0
1 1 0 0 1 1 0 0
0 0 1 1 1 1 1 1
0 0 1 1 1 1 1 1
>>A(3:4,5:6)=zeros(2,2)
A=
1 1 0 0 1 1 0 0
1 1 0 0 1 1 0 0
0 0 1 1 0 0 1 1
0 0 1 1 0 0 1 1

8
ASSIGNMENT NO: 3

Question 1: - for the function y = 0.8x3 - 12x 2 + 0.75x, calculate the value of y for the
following value of x using element by element operation; -2, -1, 0, 2, 3, 4.
Solution: - >> x = [-2 -1 0 2 3 4]
x = -2 -1 0 2 3 4
>> y = 0.8.*x.^3 – 12.*x.^2 +0.75.*x
y=
-55.9000 -13.5500 0 -40.1000 -84.1500 -137.8000
2
( x −2)
Question 2: - for the function y = , calculate the value of y for the following values of
x+4
x using element by element operation; -3, -2, 0, 2, 3, 4.
Solution: - >> x = [-3 -2 0 2 3 4];
>> y = (x.^2 - 2)./ (x+4)
y=
7.0000 1.0000 -0.5000 0.3333 1.0000 1.7500
Question 3: - The following two vector are defined in MATLAB
v = [-3 5 2] u = [4 -2 6]
check your answer by executing the following commands with MATLAB.
(1) v*u (2) v*u’ (3) v’*u
Solution: - >> v = [-3 5 2];
>> u = [4 -2 6];
1. >> v.*u
Ans =
-12 -10 12
2. >> v*u'
Ans = -10
3.>> v'*u
Ans = -12 6 -18
20 -10 30
8 -4 12

9
Question 4: -Define x and y vectors x = [1 3 5 7 9] and y = [2 5 8 11 14], then use them in
the following to calculate z using elements by element calculation,
2
xy
(1). Z =
x+ y
(2) s = x (x2 – y) – (x – y)2
Solution: - >> x = [ 1 3 5 7 9];
>> y = [2 5 8 11 14];
1. >> z = x.* y ^ 2. / (x + y)
z=
1.3333 9.3750 24.6154 47.0556 76.6957
2. >> z = x. *(x.^2 - y) - (x - y). ^ 2
z=
-2 8 76 250 578
Question 5: - Solve the following system of three linear equation:
4x – 2.5y +3z = 22.2
6x – 4y – 2z = 16.6
2x + 4y -5.55z = -11.3
Solution: - >> A = [4 -2.5 3; 6 -4 -2; 2 4 -5.5]
A=
4.0000 -2.5000 3.0000
6.0000 -4.0000 -2.0000
2.0000 4.0000 -5.5000
>> B = [22.2; 16.6; -11.3]
B = 22.2000
16.6000
-11.3000
>> linsolve (A, B)
Ans =
3.1000
-0.8000
2.6000

10
Question 6: - Solve the following system of five linear equation:
-u + 0.5v + 2w – 1.75x + y = 9.5
3u + 12v – 9w + 1.5x – 6y = -4.5
3u -1.5v +w + 1.25x + 0.5y = -11.5
3u + 2v – w + 1.5x – 3y = -3.5
6u + 3v + 2w + x + 8y = -23.5
Solution: ->> A = [ -1 0.5 2 -1.75 1; 3 12 -9 1.5 -6; 3 -1.5 1 1.25 0.5; 3 2 -1 1.5 -3; 6 3 2 1 8 ]
A=
-1.0000 0.5000 2.0000 -1.7500 1.0000
3.0000 12.0000 -9.0000 1.5000 -6.0000
3.0000 -1.5000 1.0000 1.2500 0.5000
3.0000 2.0000 -1.0000 1.5000 -3.0000
6.0000 3.0000 2.0000 1.0000 8.0000
>> B = [9.5; -4.5; -11.5; -3.5; -23.5]
B=
9.5000
-4.5000
-11.5000
-3.5000
-23.5000
>> linsolve (A, B)
Ans =
-4.0000
2.5000
4.0000
1.0000
-2.0000

11
ASSIGNMENT NO: 4

2
(x +2)
Question 1: - plot the function f(t) = , for -2 <= x <= 6.
(3+2 x 2)
Solution: - >>x = -2:0.1:6;
>>y = (x+2).^2./(3+2*x.^2);
>>plot(x, y)
>>xlabel('x')
>>ylabel('f(x)')
>> grid on

3 cos ⁡( x) 4x
Question 2: - Plot the function f(t) = −0.5 x - , for -2 <= x <= 6.
(0.5 x +e ) 7
Solution: - >> x = -2:.01:6;
>> y = 3*cos(x)./(0.5*x + exp(-0.5*x)) - 4*x/7;

12
>> plot(x,y)

Question 3: - make two separates plot of the function


x
e /2
f(x) = (x – 3) (x + 2) (4x -0.75) - one plot for -2 <= x <= 1 and one for -4<= x <= 4.
2
Solution: - >> f = @(x) (x - 3) * (x + 2) * (4*x - 0.75) - ((exp(x) / 2) / (2));
>> fplot (f, [-2,1])
>>grid on

13
Question 4: - Use fplot command to plot the function

F(x) = √|sin ( 2 x )| + cos2 (3x) for -1 <= x <= 1.

Solution: - >> fplot(@(x) sqrt(abs(sin(2*x))) + cos(3*x). ^ 2, [-1, 1]);


>>grid on

Question 5: - A parametric equation is given by


x = 1.5 sin(5t), y = 1.5 cos (3t) for 0<= t<= 2π
Solution: - >> t = linspace(0,2*pi);
>> x = 1.5*sin(5*t);
14
>> y = 1.5*cos(3*t);
>> plot (x, y)

Question 6: - A parametric equation is given by


2
3t 5t
X= 3 , y = 3
1+ t 1+ t
By plotting two curves in the same plot one for -30 ≤ t ≤ -1.6 and the other for -0.6 ≤ t ≤ -1.6
Solution: - >>x = @(t) (3*t)/(1 + t^3);
>>y = @(t) (3*t^2)/(1 + t^3);
>>hold on
>>ezplot (x, y, [-30, -1.6])
>>ezplot (x, y, [-0.6, 40])
>>hold off

15
ASSIGNMET NO: 5

Question 1: - Evaluate the following expression without using MATLAB:


Check the answer with MATLAB
A. 4+ 5 > 36/4
B. y = 4 * 2 > (12/8) + 2 > 32
C. y = 3 * (2 > 10/20) + (3 > 5)2
D. 5 * 5 – 4 * 7 <= ~ 2 * 5 - 2 + ~ 0
Solution: -A.>> % part (a)
>> 4+5>36/4
Ans = 0 (logical)
B.>> % part (b)

16
>> y = 4*2>12/8+2>3^2
y =0 (logical)
C.>> % part c
>> y = 3*(2>10/20) + (3>5) ^2
y= 3
D.>> % part d
>> 5*5-4*7<=~2*5-2+~0
Ans = 1 (logical)

Question 2: - Given a = 3, b = 2, c = 4, Evaluate the following expression without using


MATLAB. Check the Answer in MATLAB.
A. y = a + b > a – b < c
B. y = -6 < c < -2
C. y = b + c >= c > a/b
D. y = a + c == ~ (c + a ~ = (a/b) -b)
Solution: - >> a = 3;
>> b = -2;
>> c = 4;
A. >> y = a + b > a-b<c
y = 1 (logical)
B. >> y = - 6 < c < -2
y = 0 (logical)
C. >> y = b + c >= c > a/b
y = 1 (logical)
D. >> y = a + c = = ~ (c + a ~ = (a/b) - b)
y = 0 (logical)
Question 3: - given v = [ 6 -3 -2 7 0 -4 10 4] and u = [0 4 3 -2 0 -3 6 5 4]
Evaluate the following expression without MATLAB. Check the answer with MATLAB.
A. ~ (~ v)
B. u == v
C. u – v < u
D u – (v < u)
Solution: - >> v = [6 -3 -2 7 0 3 -4 10 4];
>> u = [0 4 3 -2 0 -3 6 5 4];
A.>> ~(~v)
Ans =
1×9 logical array
1 1 1 1 0 1 1 1 1
B. >> u == v
Ans =
1×9 logical array
0 0 0 0 1 0 0 0 1
C.>> u - v< u

17
Ans =
1×9 logical array
1 0 0 1 0 1 0 1 1
D.>> u - (v<u)
Ans =
0 3 2 -2 0 -3 5 5 4
Question 4: - use the vector from the problem 3 use relation operators to create a vector y
that is made up of the elements of w that are larger than or equal to the elements of v:
Solution: - >> v = [6 -3 -2 7 0 3 -4 10 4];
>> u = [0 4 3 -2 0 -3 6 5 4;
>> y = v (v <= u)
y=
-3 -2 0 -4 4
Question 5: - Evaluate the following expression without using MATLAB. Check the answer
in MATLAB.
A. 0 & 21
B. ~ - 2 > -1 & 11 > = ~ 0
C. 4 – (7/2) & 6 < 5| - 3
Solution: - A. >> 0&21
Ans = 0 (logical)
B. >> ~-2>-1&11>=~0
Ans = 1 (logical)
C. >> 4-7/2&6<5|-3
Ans = 1 (logical)

ASSIGNMENT NO: 6

Question 1: - Plot the polynomial -0.19x4 + 0.61x3 + 4x2 - 12.5x - 31 in the domain -5 < x <5.
First create a vector for x, next use polyval function to calculate y, and then use the plot
function.
Solution: -
>> x = linspace ( -5, 5);
>> y = polyval ([-0.19 0.61 4 -12.5 -31], x);
>> plot (x, y)

18
Question 2: - Plot the polynomial y= -0.001x4 + 0.051x3 - 0.76x2 - 3.8x - l.4 in the domain I
x S14.First create a vector for x, next use polyval function to calculate y, and then use the
plot function.
Solution: - >> x = linspace (1, 14);
>> y = polyval ([-0.001 0.5 1 -0.76 -3.8 -1.4], x);
>> plot (x,y)

19
Question 3: - Use MATLAB to carry out the following multiplication of two polynomials:
(5x3 + 1.5x2 + 3) (2.4x3 -2x -18)
Solution: ->> p1 = [ 5 1.5 3];
>> p2 = [2.4 -2 -18];
>> p = conv (p1, p2);
>> disp(p);
12.0000 -6.4000 -85.8000 -33.0000 -54.0000
Question 4: -Use MATLAB to carry out the following multiplication of two polynomials:
(x + l .4) (x - 0.4) x (x + 0.6) (x - 1.4)
Solution: ->> p1 = [ 1 1.4 0 -0.4 0 0.6 -1.4];
>> p2 = [1 0 -1.4];
>> p = conv (p1, p2);
>> disp(p)
1.0000 1.4000 -1.4000 -2.3600 0 1.1600 -1.4000 -0.8400
1.9600
Question 5: -Use the vectors from problem 3. Use relational operators to create a vector y
that is made up of the elements of w that are larger than or equal to the elements of v:
Solution: - >> v = [ 1 3 5 6 7 9];
>> w = [ 2 4 6 8 10 12];
>> y = w (w >= v);
>> disp(y)
2 4 6 8 10 12

20
Question 6: -Determine the solution of the equation e0.6x - √2x = 5 by Numerical Analysis
methods.

Solution: - >> fun = @(x) exp (0.6*x) - sqrt(2*x) - 5;


>> x0 = 1;
>> x = fsolve (fun, x0);
>> fprintf ('the solution is x = %f\n', x)
the solution is x = 3.380270
Question 7: -Determine the solution of the three positive roots of the equation:
1.2x3 – 9.6x2 + 21x + √ 2 x = 13
Solution: - >> coeffs = [1.2, -9.6, 21, (2^0.5)];
% Find the roots of the polynomial
>>roots = roots(coeffs);
% Print the roots
>>disp(roots)
4.0327 + 1.3284i
4.0327 - 1.3284i
-0.0654 + 0.0000i
Question 8: -Determine the positive roots of the equation x2 - 5xsin(3x) + 3 = 0
Solution: - f = @(x) (x^2) - 5*x*sin(3*x) + 3;
x0 = 0.5;
roots = fsolve(f, x0);
disp(roots)
Result:- Positive roots: 0.6434

21

You might also like