25
dr.dcd.h CS 101 Spring 2009 1 Chapter 8 Complex Numbers & 3D Plots

Chapter 8 Complex Numbers & 3D Plotshung/cs101/chap08.pdf · 2016. 4. 22. · dr.dcd.h CS 101 Spring 2009 8 Plotting Complex Data Consider the function – y(t) = e 0.2t (cos t +

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Chapter 8 Complex Numbers & 3D Plotshung/cs101/chap08.pdf · 2016. 4. 22. · dr.dcd.h CS 101 Spring 2009 8 Plotting Complex Data Consider the function – y(t) = e 0.2t (cos t +

dr.dcd.h CS 101 Spring 2009 1

Chapter 8 Complex Numbers & 3D Plots

Page 2: Chapter 8 Complex Numbers & 3D Plotshung/cs101/chap08.pdf · 2016. 4. 22. · dr.dcd.h CS 101 Spring 2009 8 Plotting Complex Data Consider the function – y(t) = e 0.2t (cos t +

dr.dcd.h CS 101 Spring 2009 2

Complex Numbers

Complex numbers are numbers with both a real and an imaginary component.

General form: operations:

c=a+b i

where a and b are both real, and i is .

A complex number can be represented as a rectangular coordinates.

A complex number can also be represented as a vector of length z and angle q where

z= √(a2+b2) and q=tan-1(b/a).

Page 3: Chapter 8 Complex Numbers & 3D Plotshung/cs101/chap08.pdf · 2016. 4. 22. · dr.dcd.h CS 101 Spring 2009 8 Plotting Complex Data Consider the function – y(t) = e 0.2t (cos t +

dr.dcd.h CS 101 Spring 2009 3

Complex Numbers2

Arithmetic operations:

Complex addition

complex subtraction

complex multiplication

complex division

Page 4: Chapter 8 Complex Numbers & 3D Plotshung/cs101/chap08.pdf · 2016. 4. 22. · dr.dcd.h CS 101 Spring 2009 8 Plotting Complex Data Consider the function – y(t) = e 0.2t (cos t +

dr.dcd.h CS 101 Spring 2009 4

Complex Numbers2

Relational operators:

Equal operator: ==

Not equal operator: ~=

Absolute value:

For a complex number z=x+yi, we define the

absolute value |z| as being the distance from z to 0 in the complex plane.

|z| = √(x2 + y2)

Page 5: Chapter 8 Complex Numbers & 3D Plotshung/cs101/chap08.pdf · 2016. 4. 22. · dr.dcd.h CS 101 Spring 2009 8 Plotting Complex Data Consider the function – y(t) = e 0.2t (cos t +

dr.dcd.h CS 101 Spring 2009 5

Some Supporting Functions

Function Descriptions

conj(z) Returns the complex conjugate of a number z.

real(z) Returns the real portion of the complex number z.

imag(z) Returns the imaginary portion of the complex number z.

isreal(z) Returns true (1) if no element of array z has an

imaginary component.

abs(z) Returns the magnitude of the complex number z.

angle(z) Retunes the angle of the complex number z.

Page 6: Chapter 8 Complex Numbers & 3D Plotshung/cs101/chap08.pdf · 2016. 4. 22. · dr.dcd.h CS 101 Spring 2009 8 Plotting Complex Data Consider the function – y(t) = e 0.2t (cos t +

dr.dcd.h CS 101 /SJC 5th Edition 6

Example 8.1

The quadratic equation

1. State the problem:

Write a program to solve for the roots of a

quadratic equation, ax2+bx+c=0.

2. Define the inputs and outputs:

Inputs will be the coefficients a, b, and c.

Outputs will be the roots of equations

3. Define the solution:

Page 7: Chapter 8 Complex Numbers & 3D Plotshung/cs101/chap08.pdf · 2016. 4. 22. · dr.dcd.h CS 101 Spring 2009 8 Plotting Complex Data Consider the function – y(t) = e 0.2t (cos t +

dr.dcd.h CS 101 /SJC 5th Edition 7

Example 8.12

Page 8: Chapter 8 Complex Numbers & 3D Plotshung/cs101/chap08.pdf · 2016. 4. 22. · dr.dcd.h CS 101 Spring 2009 8 Plotting Complex Data Consider the function – y(t) = e 0.2t (cos t +

dr.dcd.h CS 101 Spring 2009 8

Plotting Complex Data

Consider the function

y(t) = e–0.2t (cos t + i sin t)

If this function is plotted with the function plot, only

the real part will be plotted with a warning message:

Imaginary parts of complex X and/or Y

arguments ignored.

If both the real and imaginary parts of the function are of interest, then both parts are needed to be plotted.

Page 9: Chapter 8 Complex Numbers & 3D Plotshung/cs101/chap08.pdf · 2016. 4. 22. · dr.dcd.h CS 101 Spring 2009 8 Plotting Complex Data Consider the function – y(t) = e 0.2t (cos t +

dr.dcd.h CS 101 Spring 2009 9

Plotting Complex Data2

Page 10: Chapter 8 Complex Numbers & 3D Plotshung/cs101/chap08.pdf · 2016. 4. 22. · dr.dcd.h CS 101 Spring 2009 8 Plotting Complex Data Consider the function – y(t) = e 0.2t (cos t +

dr.dcd.h CS 101 Spring 2009 10

Plotting Complex Data3

Page 11: Chapter 8 Complex Numbers & 3D Plotshung/cs101/chap08.pdf · 2016. 4. 22. · dr.dcd.h CS 101 Spring 2009 8 Plotting Complex Data Consider the function – y(t) = e 0.2t (cos t +

dr.dcd.h CS 101 Spring 2009 11

Plotting Complex Data4

Page 12: Chapter 8 Complex Numbers & 3D Plotshung/cs101/chap08.pdf · 2016. 4. 22. · dr.dcd.h CS 101 Spring 2009 8 Plotting Complex Data Consider the function – y(t) = e 0.2t (cos t +

dr.dcd.h CS 101 Spring 2009 12

Plotting Complex Data4

Alternatively, the real(y) can be plotted versus imag(y) or showing abs(y) versus angle(y).

Page 13: Chapter 8 Complex Numbers & 3D Plotshung/cs101/chap08.pdf · 2016. 4. 22. · dr.dcd.h CS 101 Spring 2009 8 Plotting Complex Data Consider the function – y(t) = e 0.2t (cos t +

dr.dcd.h CS 101 Spring 2009 13

Multidimensional Arrays

Multidimensional arrays are based on the first 2D as building block, called a page.

Some useful functions:.

ones(n, m, p)

zeros(n, m. p)

rand(n, m, p)

ndims(x)

size(x)

length(x)

Page 14: Chapter 8 Complex Numbers & 3D Plotshung/cs101/chap08.pdf · 2016. 4. 22. · dr.dcd.h CS 101 Spring 2009 8 Plotting Complex Data Consider the function – y(t) = e 0.2t (cos t +

dr.dcd.h CS 101 Spring 2009 14

Multidimensional Arrays2

Some examples.

Page 15: Chapter 8 Complex Numbers & 3D Plotshung/cs101/chap08.pdf · 2016. 4. 22. · dr.dcd.h CS 101 Spring 2009 8 Plotting Complex Data Consider the function – y(t) = e 0.2t (cos t +

dr.dcd.h CS 101 Spring 2009 15

Three-Dimensional Plots

The plot creates a 2D chart.

Consider the function:

x(t) = e–0.2t cos t

y(t) = e–0.2t sin t

Page 16: Chapter 8 Complex Numbers & 3D Plotshung/cs101/chap08.pdf · 2016. 4. 22. · dr.dcd.h CS 101 Spring 2009 8 Plotting Complex Data Consider the function – y(t) = e 0.2t (cos t +

dr.dcd.h CS 101 Spring 2009 16

Three-Dimensional Plots2

A 3D line plot can be created by plot3.

Consider the same function:

x(t) = e–0.2t cos t

y(t) = e–0.2t sin t

Page 17: Chapter 8 Complex Numbers & 3D Plotshung/cs101/chap08.pdf · 2016. 4. 22. · dr.dcd.h CS 101 Spring 2009 8 Plotting Complex Data Consider the function – y(t) = e 0.2t (cos t +

dr.dcd.h CS 101 Spring 2009 17

Three-Dimensional Surfaces

Surface, mesh, and contour plots are convenient ways to represent data that is a function of two variables, f(x,y,z).

Arrays x, y, and z must have the identical size.

The x-y grid can be created by meshgrid.

Page 18: Chapter 8 Complex Numbers & 3D Plotshung/cs101/chap08.pdf · 2016. 4. 22. · dr.dcd.h CS 101 Spring 2009 8 Plotting Complex Data Consider the function – y(t) = e 0.2t (cos t +

dr.dcd.h CS 101 Spring 2009 18

Three-Dimensional Surfaces2

Consider the 3D sinc function as a folded sheet

z(x, y) = sin(x + y)/(x + y)

Page 19: Chapter 8 Complex Numbers & 3D Plotshung/cs101/chap08.pdf · 2016. 4. 22. · dr.dcd.h CS 101 Spring 2009 8 Plotting Complex Data Consider the function – y(t) = e 0.2t (cos t +

dr.dcd.h CS 101 Spring 2009 19

Three-Dimensional Surfaces3

Consider the 3D sinc function as a rain drop.

z(x, y) = sin(sqrt(x2+y2))/sqrt(x2+y2)

Page 20: Chapter 8 Complex Numbers & 3D Plotshung/cs101/chap08.pdf · 2016. 4. 22. · dr.dcd.h CS 101 Spring 2009 8 Plotting Complex Data Consider the function – y(t) = e 0.2t (cos t +

dr.dcd.h CS 101 Spring 2009 20

Three-Dimensional Surfaces4

Draw the 3D sinc function by using surf.

z(x, y) = sin(sqrt(x2+y2))/sqrt(x2+y2)

Page 21: Chapter 8 Complex Numbers & 3D Plotshung/cs101/chap08.pdf · 2016. 4. 22. · dr.dcd.h CS 101 Spring 2009 8 Plotting Complex Data Consider the function – y(t) = e 0.2t (cos t +

dr.dcd.h CS 101 Spring 2009 21

Three-Dimensional Surfaces4

Draw the 3D sinc function by using contour.

z(x, y) = sin(sqrt(x2+y2))/sqrt(x2+y2)

Page 22: Chapter 8 Complex Numbers & 3D Plotshung/cs101/chap08.pdf · 2016. 4. 22. · dr.dcd.h CS 101 Spring 2009 8 Plotting Complex Data Consider the function – y(t) = e 0.2t (cos t +

dr.dcd.h CS 101 Spring 2009 22

Three-Dimensional Surfaces5

Draw a 3D sphere function.

x=r*cos(q)*cos(f)

y=r*cos(q)*sin(f)

z=r*sin(q)

q=[–p, p]

f=[–p/2, p/2]

Page 23: Chapter 8 Complex Numbers & 3D Plotshung/cs101/chap08.pdf · 2016. 4. 22. · dr.dcd.h CS 101 Spring 2009 8 Plotting Complex Data Consider the function – y(t) = e 0.2t (cos t +

dr.dcd.h CS 101 Spring 2009 23

Three-Dimensional Surfaces6

Page 24: Chapter 8 Complex Numbers & 3D Plotshung/cs101/chap08.pdf · 2016. 4. 22. · dr.dcd.h CS 101 Spring 2009 8 Plotting Complex Data Consider the function – y(t) = e 0.2t (cos t +

dr.dcd.h CS 101 Spring 2009 24

Three-Dimensional Surfaces7

Page 25: Chapter 8 Complex Numbers & 3D Plotshung/cs101/chap08.pdf · 2016. 4. 22. · dr.dcd.h CS 101 Spring 2009 8 Plotting Complex Data Consider the function – y(t) = e 0.2t (cos t +

dr.dcd.h CS 101 Spring 2009 25

Homework Assignment #15

8.5 Exercises

Page 345: 8-1, 8-2, 8-14, 8-15

This assignment is for your reference.