Professional Documents
Culture Documents
Experiment No. (4) Examples: Example 4.1
Experiment No. (4) Examples: Example 4.1
Experiment No. (4) Examples: Example 4.1
Experiment No. ( 4 )
Examples
Example 4.1
If w is a complex matrix given as
1+𝑗 2 − 2𝑗
3 + 2𝑗 4 + 3𝑗
then we can represent it in MATLAB as
If the entries in a matrix are complex, then the “prime” (‘) operator produces the conjugate transpose.
Thus,
>> wp = w'
For the unconjugated transpose of a complex matrix, we can use the point transpose (.') command. For
example,
>> wt = w.'
Example 4.2
The voltage, v, across a resistance is given as (Ohm’s Law), = 𝑅𝑖 , where i is the current and 𝑅 the
resistance. The power dissipated in resistor 𝑅 is given by the expression
𝑃 = 𝑅𝑖
If 𝑅 = 10 Ohms and the current is increased from 0 to 10 A with increments of 2A, write a MATLAB
program to generate a table of current, voltage and power dissipation.
MATLAB Script
Note that : row 1 of the variable "sol" constitutes the current values, row 2 constitutes the voltages, and
row 3 constitutes the power dissipation values.
1
Experiment No. 4 | Computer Lab.
Example 4.3
For an R-L circuit, the voltage v(t ) and current i(t ) are given as
𝑣(𝑡) = 10 cos(337𝑡)
𝑖(𝑡) = 5 cos(337𝑡 + 60°)
Sketch v(t ) and i(t ) for t = 0 to 20 milliseconds.
% RL circuit
% current i(t) and voltage v(t) are generated; t is time
t = 0:1e-3:20e-3;
v = 10*cos(337*t);
%a_rad = (60*pi/180); % angle in radians
i = 5*cos(337*t + deg2rad(60));
plot(t,v,'b-*',t,i,'r-o')
title('Voltage and Current of an RL circuit')
xlabel('Sec')
ylabel('Voltage(V) and Current(mA)')
legend('Voltage(V)', 'Current(mA)')
grid
Polynomial roots
r = roots(p)
returns the roots of the polynomial represented by 𝑝 as a column vector.
Input 𝑝 is a vector containing n+1 polynomial coefficients, starting with the coefficient of 𝑥 .
A coefficient of 0 indicates an intermediate power that is not present in the equation.
For example,
𝑝 = [3 2 − 2] represents the polynomial 3𝑥 + 2𝑥 − 2.
The roots function solves polynomial equations of the form 𝑝 𝑥 + ⋯ + 𝑝 𝑥 + 𝑝
Polynomial equations contain a single variable with nonnegative exponents.
Example 4.4
2
2nd Year | Electrical Engineering Dept.
Example 4.5
Solve the equation 𝑥 − 1 = 0
Create a vector to represent the polynomial, then find the roots.
p = [1 0 0 0 -1];
r = roots(p)
Example 4.6
For the circuit shown below, find the nodal voltages 𝑉 , 𝑉 , and 𝑉
Solution
Using KCL and assuming that the currents leaving a node are positive, we have
3
Experiment No. 4 | Computer Lab.
v=
404.2857
350.0000
412.8571
Prepared by:
Dr. Intessar Al-Iedani