3 8
1.
2
100
7 j
42 B A 2
B'
h) calculate A-1 .B
inv (A) * B
i) multiply first element at the third row of A by the third
element at the first column of B
A (3,1) * B (3, 1) % scalar multiplication, so no
need to put the . operator
2-Using MATLABE function file line to evaluate the complex
number Z in both polar and rectangular form given as
Z=(1-i).e3 sin-1(0.5).(3+4j)-1.e-j30 .5450
Solution:
Z1 = (1 i) * exp (3*pi)
Z2 = asin (0.5) * 1 / (3 + 4* j) % asin is the representation of
sin -1 in Matlab
Z3 = exp ( - j * 30) * 5 exp (j * 45 * pi / 180) % theta rad = theta
degree * pi /180
Z = Z1 * Z2 * Z3
II-Polynomials operations and symbolic
Solution:
Note: Symbolic Math will not come in the exam, so
question 10 is not required
5- plot (x1,f)
6- xlabel ('x1')
7- ylabel ('f (x) ')
8- title (' exponential_sinusoidal function ')
9- legend (' f (x) ')
10hold on
11plot (x2,y)
12xlabel ('x2')
13ylabel ('y ')
14title (' absolute cubic function ')
15legend (' y ')
2- Write a script file to plot the polynomial
Over the range -6 <= x < 6with spacing of 0.01
Solution:
1- x = -6 : 0.01: 6
2- p = [2 , 2, -100, -2, -7, 90 ] % polynomial of degree
5 has 6 coefficients
3- y = polyval (p , x)
4- plot (x, y)
3-Write a functional file to evaluate n factorial (i.e. n!) where
n ! = n (n-1) (n-2)
(n-3).(2 )(1)
Solution:
function fact = factorial (n)
n = input (' enter a number ')
fact = 1
for i = 1 : n
fact = fact * i
end % end of the for loop
fact % the function returns the value of fact
end % end of the function file
4- Write a MATLAB function to add all the odds numbers from 0
to n (at each run n
is changed) Add all the terms in the series
Solution:
12345-
x2
Z
x=0
Solution:
12345678-
Solution:
1- n = input ('Enter the number of terms of the Fibonacci
series')
2- A (1) = 1
3- A (2) = 1
4- for i = 3: n
5- A (i) = A (i-1) + A (i-2)
6- end % end of the for loop
7- disp (A) % display the vector A
Part_ 3 application of Function and M. files in
electronics.
10
11
For the series RLC circuit the transfer function (T.F) is given as:
13
16
Solution:
General Simulink Model:
Source
(input
waveforms or
imported
from an
external file )
System
(interconnected
links between
different blocks
like integrator,
derivative,
Multiplexer,
Sink
(output either on
scope or exported
to an external file)
A Ramp block to input the temperature signal, from the Sources library
A Constant block to define a constant of 32, also from the Sources library
17
A Gain block to multiply the input signal by 9/5, from the Math Operations
library
A Sum block to add the two quantities, also from the Math Operations library
Assign parameter values to the Gain and Constant blocks by opening (doubleclicking) each block and entering the appropriate value. Then, click the OK button to
apply the value and close the dialog box.
Now, connect the blocks.
The Ramp block inputs Celsius temperature. Open that block and change the Initial
output parameter to 0. The Gain block multiplies that temperature by the constant
9/5. The Sum block adds the value 32 to the result and outputs the Fahrenheit
temperature.
Open the Scope block to view the output. Now, choose Run from
the Simulation menu to run the simulation. The simulation runs for 10 seconds.
18
2
A
7
4 2
4 100
9 7
8 42 B A 2
(3 j 4)( 6 j 6)
7 j10
(2 j1) j 2
11 4
12 2
17
30
10
42 B e A
f (x)
f1 = [14, -6, 3, 4]
f2 = [5, 7, -4]
F = conv (f1, f2)
6 x 6
and function
for
2-Write a functional file to evaluate n factorial (i.e. n!) where
n ! = n (n-1) (n-2)
(n-3).(2 )(1)
x
7!
3! 4!
1 1 1
1
..........
where n 0,1,2.....
3 5 7
2n 1
24 5
20 13
9 11
24
3
2
24 5
20 13
9 11
24
3
2
24 5
20 13
9 11
24
3
2
12
where
5- Write a for loop that is equivalent to the command max(A)
A
12
where
6- Write a for loop that is equivalent to the command min(A)
A
where
12
v(t ) 10 (1 e 0.2t )
6 x 6
23
14
to 10
19
cm
-3
24
25