DOC PREVIEW
UE EE 210 - EE 210 – Circuits Working with Complex Numbers and Matrices in Scilab

This preview shows page 1 out of 4 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 4 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 4 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

EE 210 – CircuitsWorking with Complex Numbers and Matrices in ScilabTony RichardsonUniversity of EvansvilleBy default, Scilab accepts complex numbers only in rectangular form. Use %i to represent the complex number i.-->5+4*%i ans = 5. + 4.iYou can define two additional functions, p2z() and z2p(), that make it easy to enter and display numbers in polar form. The code for these functions is included on the last page of this tutorial. (You can also find the code as a ZIP file on the course webpage on the Harlaxton server. Follow the installation instructions in the README.txt file. --DJH)To enter the complex number (1∡45) using the p2z() function, just enter:-->x = p2z(1,45) x = 0.7071068 + 0.7071068i To display a complex number in polar form use the z2p() function:-->z2p(x)! 1. 45. ! ans = 0.7071068 + 0.7071068iNote that the magnitude is displayed first and that the phase angle is in degrees. The z2p() function just displays the number in polar form. It returns the complex number in standard rectangular form.You can use the p2z() function to enter a complex number in polar form at any point you might use a number in rectangular form. Here are some examples:-->z = (7+8*%i + p2z(20, -30))/p2z(5, 45) z = 3.1565965 - 3.7222819i-->z2p(z);! 4.8805209 - 49.701147 !-->volts = [p2z(10,45); p2z(20,-30); p2z(100,0)] volts =11/12/2007 1 of 4! 7.0710678 + 7.0710678i !! 17.320508 -10.i !! 100. !The first two results indicate that z is equal to 3.1566 – 3.72228i or (4.8805∡-49.70). The last example illustrates how a voltage column array can be defined. p2z() will also accept matrix arguments. The first argument should contain the magnitudes and the second argument should contain the phase angles, the volts array in the previous example could be defined as:-->volts = p2z([10 20 100]',[45 -30 0]') volts =! 7.0710678 + 7.0710678i !! 17.320508 -10.i !! 100. !z2p() will accept an array of complex numbers. It displays an array of magnitude and phase pairs:-->z2p(volts);! 10. 45. !! 20. - 30. !! 100. 0. !By default, z2p() returns the original complex matrix in standard rectangular form. It only displays the values in polar form. However, if two return arguments are used the magnitude and phase angles are returned in separate matrices:-->[m a] = z2p(volts) a =! 45. !! - 30. !! 0. ! m =! 10. !! 20. !! 100. !Be careful when using the apostrophe (') operator with complex arrays and matrices. It returns the complex-conjugate transpose of a complex array instead of just the transpose of the array or matrix. If you want the transpose be sure to use the dot-apostrophe (.') operator. For a real array the apostrophe and dot-apostrophe operators give identical results. When applied to a single complex number (instead of an array) the apostrophe operator gives the complex-conjugate of the number.Here's a final example that illustrates how to use Scilab to solve a sinusoidal steady-state circuit problem. Suppose we want to find the branch phasor currents in the phasor domain circuit shown in Figure 1.11/12/2007 2 of 4j12 Ω 20 Ω80 Ω-j20 ΩVA =100 ∠−90°VB =500 ∠ 0°IAIBICFigure 1: Example Frequency Domain CircuitWe will use mesh analysis to solve this problem. We can write the following set of mesh equations by inspection:100∡−90 = j12 IA−IC80 IA−IB−500∡0 = 80IB−IA20  IB−IC0 = − j20 IC20  IC−IB j12 IC−IACollecting terms corresponding to each phasor current yields:100∡−90 =  j1280 IA −80 IB − j12 IC−500∡0 = −80 IA 8020 IB −20 IC0 = − j12 IA −20 IB − j2020 j12 ICInstead of simplifying these equations, let's go directly to Scilab. We can define the voltage array as:-->V = [p2z(100, -90); p2z(-500, 0); 0];The p2z() function was used to allow us to easily enter in the voltage array using magnitude and phase angle values.The elements of Z are formed directly from the mesh equations above (let Scilab do the work of combining the terms for you):-->Z = [%i*12+80, -80, -%i*12--> -80, 80+20, -20--> -%i*12, -20, -%i*20+20+%i*12];Although not necessary here, the p2z() function could have been used to allow us to easily enter in any values that were in polar form.Since V = Z I, then I = Z-1 V. Computing the currents and then using z2p() to display the currents in polar form yields:-->I = inv(Z)*V;-->z2p(I);! 22.022716 - 129.47246 !! 24.020824 - 129.25584 !11/12/2007 3 of 4! 25.495098 - 78.690068 !The currents are therefore equal to IA = (22.0∡-129.5), IB = (24.0∡-129.3), and IC = (25.5∡ -78.7).Scilab Complex Number RoutinesNote: The versions of these routines that are available for download have more comments, better error checking, and support additional options. Only the core code is shown here to limit the size of this document.// A = p2z(R,Theta) - Convert from polar to rectangular form.// R is a matrix containing the magnitudes// Theta is a matrix containing the phase angles (in degrees).function [A] = p2z(R,Theta) if argn(2) <> 2 then error("incorrect number of arguments."); end if ~and(size(R) == size(Theta)) then error("arguments must be of the same dimension."); end A = R.*exp(%i*%pi*Theta/180.);endfunction// [R, Theta] = z2p(A) - Display polar form of complex matrix.function [R, Theta] = z2p(A) if argn(1) == 1 then // Only a single return argument. // Display the mag and phase in adjacent columns. Theta = zeros(A); // Protect against 0 entries i = (A <> 0); Theta(i) = atan(imag(A(i)),real(A(i)))*180./%pi; disp(matrix([abs(A); Theta],size(A,1),2*size(A,2))); R = A; elseif argn(1) == 2 then // With two return arguments, the mag and phase are in stored in // separate matrices // Protect against 0 entries i = (A <> 0); Theta = zeros(A); Theta(i) = atan(imag(A(i)),real(A(i)))*180./%pi; R = abs(A); else error("invalid number of return arguments"); endendfunction11/12/2007 4 of


View Full Document

UE EE 210 - EE 210 – Circuits Working with Complex Numbers and Matrices in Scilab

Download EE 210 – Circuits Working with Complex Numbers and Matrices in Scilab
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view EE 210 – Circuits Working with Complex Numbers and Matrices in Scilab and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view EE 210 – Circuits Working with Complex Numbers and Matrices in Scilab 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?