1 / 17

CSE/Math 1560: Introduction to Computing for Mathematics and Statistics Winter 2011

Suprakash D at ta datta@cse.yorku.ca Office: CSEB 3043 Phone: 416-736-2100 ext 77875 Course page: http://www.cse.yorku.ca/course/1560. CSE/Math 1560: Introduction to Computing for Mathematics and Statistics Winter 2011. Announcements. 1. Midterm: Mar 1, 2:30-3:30 pm, room TBA.

lmitchell
Download Presentation

CSE/Math 1560: Introduction to Computing for Mathematics and Statistics Winter 2011

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Suprakash Datta datta@cse.yorku.ca Office: CSEB 3043 Phone: 416-736-2100 ext 77875 Course page: http://www.cse.yorku.ca/course/1560 CSE/Math 1560:Introduction to Computing for Mathematics and Statistics Winter 2011 Math/CSE 1560, Winter 2011

  2. Math/CSE 1560, Winter 2011 Announcements 1. Midterm: Mar 1, 2:30-3:30 pm, room TBA. 2. Please practice the sample exercises before going to the labs. 3. Labs next week: everything covered in class before Feb 9. Focus on writing procedures and functions.

  3. Math/CSE 1560, Winter 2011 Last class 1. If-then statement • Next: Sets, lists and sequences. Ch 4 in the textbook.

  4. Math/CSE 1560, Winter 2011 Programming principle • print_toss := x -> piecewise(x = 1, "head", x = 0, "tail") flip := proc () local HT, x; HT := rand(0 .. 1); x := HT(); print_toss(x) end proc; • Note that print_toss is defined outside the procedure.

  5. Math/CSE 1560, Winter 2011 Consider this variant • flip2 := proc () • local HT, x, print_toss; • print_toss := x-> piecewise(x = 1, "head", x = 0, "tail") ; • HT := rand(0 .. 1); • x := HT(); • print_toss(x); • end proc • Which is the better way?

  6. Math/CSE 1560, Winter 2011 Global variables • Defined within a proc, visible outside the proc. • Use with care.

  7. Math/CSE 1560, Winter 2011 Two more functions • trunc(x) • frac(x)

  8. Math/CSE 1560, Winter 2011 Sets • Enclosed in {}, separated by commas • e.g.: {22,5,7,10,3,-1} • Sets cannot have duplicates • > set1 := {1, 2, 3}; {1, 2, 3} > set2 := {1, 2, 3, 2, 1}; {1, 2, 3} > set3 := {3, b, a, 2}; {2, 3, a, b}

  9. Math/CSE 1560, Winter 2011 Set operations • S union T, S intersect T, S minus T • Equality: evalb(S=T); • Membership: member(1,set1) OR • evalb(1 in set1)

  10. Math/CSE 1560, Winter 2011 Adding and removing elements • Use the union and minus.

  11. Math/CSE 1560, Winter 2011 The map function • map(func,set) • e.g. • > mySeq := {seq(K, K = 1 .. 10)}; • {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} • > map(x-> x^2, mySeq); • {1, 4, 9, 16, 25, 36, 49, 64, 81, 100}

  12. Math/CSE 1560, Winter 2011 Example: remove negative values from a set • Steps: • Write out the sketch of the algorithm • Think of the most efficient way to implement the algorithm

  13. Math/CSE 1560, Winter 2011 Code • > f1 := x-> piecewise(x < 0, -100, x => 0, x); • > set1 := {-4, -3, -2, 5, 6, 7}; • {-4, -3, -2, 5, 6, 7} • > set2 := map(f1, set1); • {-100, 5, 6, 7} • > set2 := set2 minus {-100}; • {5, 6, 7}

  14. Math/CSE 1560, Winter 2011 More on seq() • seq(func,index=a..b) • E.g.: • seq(n^2,n=1..10) • Question: For which values of n is 1+x^n factorizable?

  15. Math/CSE 1560, Winter 2011 Code seq(factor(x^n+1), n = 2 .. 12); Does this imply all coefficients or 1 or –1 for all n?

  16. Math/CSE 1560, Winter 2011 No!

  17. Math/CSE 1560, Winter 2011 Exercise • Write a procedure that takes as input an integer n and outputs a set of all primes in1..n. • (there is a Maple function called ithprime(i) that you should not use, but may be aware of).

More Related