Complex Number Arithmetic

Slides:



Advertisements
Similar presentations
Fall 2008Programming Development Techniques 1 Topic 12 Multiple Representations of Abstract Data – Complex Numbers Section
Advertisements

Structure and Interpretation of Computer Programs* Section 2.4 – 2.5 Presenter: Xiang Zhang 05/04/ * Harold A., Gerald J. S., Julie S.. Structure.
8.3 THE COMPLEX PLANE & DEMOIVRE’S THEOREM Precalculus.
데이타를 여러방식으로 구현할 때 Multiple Representations 데이터 구현방식마다 꼬리표를 붙이고. 데이터 속내용 감추기 원리를 유지하면서. 예를 들어 complex number data 구현방안들을 생각해 보자 – complex number 만들기 make-from-real-imag:
Getting started with ML ML is a functional programming language. ML is statically typed: The types of literals, values, expressions and functions in a.
11.2 Geometric Representations of Complex Numbers.
מבוא מורחב למדעי המחשב בשפת Scheme תרגול 7. Data directed programming Section 2.4, pages ,2.5.2 pages (but with a different example)
מבוא מורחב 1 Lecture #13. מבוא מורחב 2 Multiple representations of data.
Polar Coordinates (MAT 170) Sections 6.3
מבוא מורחב למדעי המחשב בשפת Scheme תרגול 10. Data directed programming Message passing Section 2.4, pages ,2.5.2 pages (but with.
מבוא מורחב למדעי המחשב בשפת Scheme תרגול 7. Outline Symbols Data Directed Programming, Message Passing.
Cylindrical Coordinate Coordinate Systems. Representing 3D points in Cylindrical Coordinates.  r Start from polar representations in the plane.
POLAR COORDINATES (Ch )
Scheme Tutorial. Goals Combine several simple ideas into one compound idea to obtain complex ideas Bring two ideas together to obtain relations Seperate.
1 Lisp Functions –Built-in functions –Defining functions –Function Evaluation and Special Forms defun, if Control statements –Conditional if, cond –Repetition.
Introduction to Scheme Lectures on The Scheme Programming Language, 2 nd Ed. R. Kent Dybvig.
Chapter 9 Polynomials. What are polynomials? Poly- nomial- What are monomials Mono- nomial.
CS220 Programming Principles 프로그래밍의 이해 2002 년 가을학기 Class 8 한 태숙.
The Teacher CP4 Binary and all that… CP4 Revision.
Lecture 13: Complex Numbers and Sinusoidal Analysis Nilsson & Riedel Appendix B, ENG17 (Sec. 2): Circuits I Spring May 13, 2014.
COP4020 Programming Languages Functional Programming Prof. Xin Yuan.
Fall 2008Programming Development Techniques 1 Topic 13 Multiple Representations of Abstract Data – Tagged Data Section
Slide Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
1/38. 2/38 Tagged Data Tag: a symbol in a data structure that identifies its type Why we need tags Extended example: evaluating arithmetic expressions.
5.7 Completing the Square Ch. 6 Notes Page 38 P38 6.1: Polynomial Functions.
SICP Tagged data Why do we need tags Concept of tags Extended example.
Fall 2008Programming Development Techniques 1 Topic 14 Multiple Representations of Abstract Data – Data Directed Programming and Additivity Section
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
Applications of Trigonometric Functions
2.2 The Complex Plane Objective: to find the magnitude and argument of a complex number.
160 as a product of its prime factors is 2 5 x 5 Use this information to show that 160 has 12 factors.
EXPRESSIONS, FORMULAS, AND PROPERTIES 1-1 and 1-2.
IMAGINARY NUMBERS AND DEMOIVRE’S THEOREM Dual 8.3.
CS 125 Lecture 3 Martin van Bommel. Overflow In 16-bit two’s complement, what happens if we add =
1/38 Tagged Data Tag: a symbol in a data structure that identifies its type Why we need tags Extended example: evaluating arithmetic expressions.
Degrees of a Monomial. Degree of a monomial: Degree is the exponent that corresponds to the variable. Examples: 32d -2x 4 16x 3 y 2 4a 4 b 2 c 44 has.
SICP Tagged data Why do we need tags Concept of tags Extended example.
1 Recursive Data Structures CS 270 Math Foundations of CS Jeremy Johnson.
Addition, Subtraction, and Multiplication of Polynomials
Numbers How does computer understand numbers? Knows only two symbols
CS314 – Section 5 Recitation 10
Vectors, Roots of Unity & Regular Polygons
Factoring Polynomials
Tagged Data Tag: a symbol in a data structure that identifies its type
ECE 1304 Introduction to Electrical and Computer Engineering
6.001 SICP Object Oriented Programming
Racket CSC270 Pepper major portions credited to
Complex Numbers Real part Imaginary part
11.2 – Geometric Representation of Complex Numbers
Polar Coordinates.
Honors Precalc: Warm-Up
Trigonometry Section 11.2 Write and graph complex numbers in polar form. Multiply complex numbers. To represent the complex number a+ bi graphically,
BCD = Binary Coded Decimal
Lecture 18.
Lecture 16: Tables and OOP
Convert to rectangular:
7.6 Powers and Roots of Complex Numbers
Mutable Data (define mylist (list 1 2 3)) (bind ((new (list 4)))
Starter Using the fingers on only one hand, what is the highest number you can count to? Rules: You must start at 1 You must count sequentially (i.e.
Lecture 12: Message passing The Environment Model
Solving Special Cases.
Lecture 11: Multiple representations of abstract data Message passing Overloading Section 2.4, pages ,2.5.2 pages מבוא.
Copyright © 2017, 2013, 2009 Pearson Education, Inc.
Warm Up Factor: 6x4 – 18x3 + 12x2 Factor: 16x4 – 81
Convert the following to rectangular form:
Complex Numbers MAΘ
Complex Numbers.
Complex Numbers What if we want to add two sinusoids?
Graphing Polar Coordinates
Dispatch on Type (one-less x) => x-1 if x is a <number>
Presentation transcript:

Complex Number Arithmetic Two natural representations: • rectangular: (real,imag) • polar: (norm,arg) z = (z) + i ·(z) = |z| ·e i ·arg(z)

imag z |z| (z) arg(z) (z) real z = (z) + i ·(z) = |z| ·e i ·arg(z)

Abstract Types (define-class <complex> (<number>)) (define-class <rect> (<complex>) (real <float>) (imag <float>)) (define-class <polar> (<complex>) (norm <float>) (arg <float>)) <object> <number> <integer> <float> <rat> <complex> <rect> <polar>

(define (make-polar <function>) (method ((n <number>) (a <number>)) (make <polar> norm: (as <float> n) arg: (as <float> a)))) (define (make-rect <function>) (method ((r <number>) (i <number>)) (make <rect> real: (as <float> r) imag: (as <float> i))))

<rect> <polar> real slot convert reference imag slot convert norm convert slot arg convert slot

(define-generic-function real (x)) (add-method real (method ((x <rect>)) (get-slot real: x))) (define-generic-function imag (x)) (add-method imag (get-slot imag: x)))

Dylan does this for you! (define-generic-function real (x)) (add-method real (method ((x <rect>)) (get-slot real: x))) (define-generic-function imag (x)) (add-method imag (get-slot imag: x))) Dylan does this for you!

(add-method real (method ((z <polar>)) (* (norm z) (cos (arg z))))) (add-method imag (* (norm z) (sin (arg z))))) (add-method norm (method ((z <rect>)) (sqrt (+ (square (real z)) (square (imag z)))))) (add-method arg (arctan (/ (imag z) (real z)))))

(define (mul-complex <function>) (method ((x <complex>) (y <complex>)) (make-polar (* (norm x) (norm y)) (+ (arg x) (arg y))))) (define (add-complex <function>) (make-rect (+ (real x) (real y)) (+ (imag x) (imag y)))))

or better... (define-generic-function add (x y)) (add-method add (method ((x <number>) (y <number>)) (+ x y))) (add-method add add-rat) (add-method add add-complex) or better... (add-method binary+ add-rat) (add-method binary+ add-complex)

Coercions — the generic function as (as <float> 1) => 1.0 (as <character> 100) => d <integer>  <rat>  <float>  <complex> (add-method as (method ((t (singleton <rat>)) (a <integer>)) (make-rat a 1))) (add-method binary+ (method ((a <integer>) (b <rat>)) (+ (as <rat> a) b))) (method ((a <rat>) (b <integer>)) (+ a (as <rat> b))))

Polynomial Arithmetic (define-class <term> (<object>) (degree <integer>) (coeff <object>)) (define (add-term <function>) (method ((t1 <term>) (t2 <term>)) (make <term> degree: (degree t1) coeff: (+ (coeff t1) (coeff t2)))))

(define <termlist> <list>) (define (first-term <function>) (method ((t <termlist>)) (head t))) (define (rest-terms <function>) (method ((t <termlist>)) (tail t))) (define empty-termlist? null?)

(define (add-terms <function>) (method ((l1 <termlist>) (l2 <termlist>)) (cond ((empty-termlist? l1) l2) ((empty-termlist? l2) l1) (else: (bind (((t1 <term>) (first-term l1)) ((t2 <term>) (first-term l2)) ((r1 <termlist>) (rest-terms l1)) ((r2 <termlist>) (rest-terms l2))) (cond ((< (degree t1) (degree t2)) (adjoin-term t1 (add-terms r1 l2))) ((< (degree t2) (degree t1)) (adjoin-term t2 (add-terms l1 r2))) (adjoin-term (add-term t1 t2) (add-terms r1 r2)))))))))

(define-class <poly> (<object>) (poly-variable <symbol>) (poly-terms <termlist>)) (define (same-variable? <function>) (method ((p1 <poly>) (p2 <poly>)) (= (poly-variable p1) (poly-variable p2)))) (define (add-poly <function>) (if (same-variable? p1 p2) (make <poly> poly-variable: (poly-variable p1) poly-terms: (add-terms (poly-terms p1) (poly-terms p2))) (error "Polynomials not in same variable")))) (add-method binary+ add-poly)