Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Useful functions in MATLAB related to complex numbers MATLAB functionDescriptionExample (MATLAB outputs in red) real(x)Real part of complex number A.

Similar presentations


Presentation on theme: "1 Useful functions in MATLAB related to complex numbers MATLAB functionDescriptionExample (MATLAB outputs in red) real(x)Real part of complex number A."— Presentation transcript:

1 1 Useful functions in MATLAB related to complex numbers MATLAB functionDescriptionExample (MATLAB outputs in red) real(x)Real part of complex number A = 3 + 4i; X = real(A) X = 3 imag(x)Imaginary part of complex number A = 3 + 4i; X = imag(A) X = 4 abs(x)Magnitude of a complex number X = abs(3+4i) X = 5 angle(x)Angle of a complex number in radians Alpha = angle(3+4i)*180/pi alpha = conj(x)Complex conjugate of complex number A = 3+4i A = i X = conj(A) X = i Complex Numbers in MATLAB We will begin this section by looking at several useful functions in MATLAB related to complex numbers. EGR 272 – Complex Numbers and AC Circuits using MATLAB

2 MATLAB functionDescriptionExample (MATLAB outputs in red) [theta, r] = cart2pol(x, y)Converts from rectangular to polar form where theta is in radians [Radians,Mag]=cart2pol(3,4) Radians = Mag = 5 Degrees=Radians*180/pi Degrees = Note: so 3 + 4i = [x, y] = pol2cart(theta, r)Converts from polar to rectangular form where theta is in radians [a,b]=pol2cart(30*pi/180,10) a = b = Note: so = i complex(a,b)Form complex data from real and imaginary parts X = complex(3,4) X = i A = [3;-3;-3;3]; B = [4;4;-4;-4]; C = complex(A,B) C = i i i i Useful functions in MATLAB related to complex numbers 2 EGR 272 – Complex Numbers and AC Circuits using MATLAB

3 Useful operations in MATLAB related to complex numbers MATLAB operationsDescriptionExample (MATLAB outputs in red) Exponentiation(^)Raise a complex number to a power X = (1+2i)^2 X = i Arithmetic operations -Addition (+) -Subtraction (-) -Multiplication (*) -Division (/) Converts from polar to rectangular form where theta is in radians A=3+4i; B=2+6i; A+B ans = i A-B ans = i A*B ans = i A/B ans = i Exponential polar formX = 10*exp(30i*pi/180) X = i [Real,Imag]=pol2cart(30*pi/180,10) Real = Imag = Note: So 10e j30 = EGR 272 – Complex Numbers and AC Circuits using MATLAB

4 Printing Complex Numbers in MATLAB Some options for printing complex numbers in MATLAB include: 1)Do not suppress printing and accept the default format (rectangular form): 2)Display using fprintf (not perfect, but may be sufficient in some cases) 4 EGR 272 – Complex Numbers and AC Circuits using MATLAB

5 Printing Complex Numbers in MATLAB Some options for printing complex numbers in MATLAB include: 3.Convert complex number to a string using num2str( ) and print using %s: 5 EGR 272 – Complex Numbers and AC Circuits using MATLAB

6 AC Circuit Analysis Procedure: 1) Draw the phasor circuit (showing voltage and current sources as phasors and using complex impedances for the components). 2) Analyze the circuit in the same way that you might analyze a DC circuit. 3) Convert the final phasor result back to the time domain. Application of Complex Numbers: AC Circuit Analysis (Phasor Analysis) Example: Use the total current using phasor analysis by hand. 6 EGR 272 – Complex Numbers and AC Circuits using MATLAB Solution: See next slide

7 7 EGR 272 – Complex Numbers and AC Circuits using MATLAB 50 0 V j25-j50 j20 I Solution: phasor circuit:

8 Example: Use MATLAB to solve for the total phasor current. 8 EGR 272 – Complex Numbers and AC Circuits using MATLAB


Download ppt "1 Useful functions in MATLAB related to complex numbers MATLAB functionDescriptionExample (MATLAB outputs in red) real(x)Real part of complex number A."

Similar presentations


Ads by Google