Presentation is loading. Please wait.

Presentation is loading. Please wait.

Math 15 Introduction to Scientific Data Analysis Lecture 9 Python Programming – #3 University of California, Merced.

Similar presentations


Presentation on theme: "Math 15 Introduction to Scientific Data Analysis Lecture 9 Python Programming – #3 University of California, Merced."— Presentation transcript:

1 Math 15 Introduction to Scientific Data Analysis Lecture 9 Python Programming – #3 University of California, Merced

2 UC Merced2 Schedule December 17 6-9pm Quiz #6 There will be a lab this week!

3 UC Merced3  After two weeks of Python Programming experience, what did you think? python

4 UC Merced4 But ….  Current biology or other science disciplines require researchers to have strong quantitative skills!  You cannot ignore Math or other quantitative analysis subjects if you want to study Biology!

5 UC Merced5 October, 2007 Bis 180

6 UC Merced6  Any Questions?

7 UC Merced7 Assignment #5 due November 2 nd, 2007! Assignments & their materials!

8 UC Merced8 Click This!

9 UC Merced9 First, Retrieve this file. For submission, first click this to attach your python codes.

10 UC Merced10 Click this to browse your file and attach your python file

11 UC Merced11 Then hit this to continue!

12 UC Merced12 To submit

13 UC Merced13 Any Questions?

14 UC Merced14 Math 15 Now till the end of Fall semester  Four more Labs  One more Assignment ( HW #7 due November 18) Total of 7 assignments  Two more Quizzes (Next week and Nov. 28) Total of 6 quizzes  Project #2 (due December 7)  Final Exam – December 17 th

15 UC Merced15 Grading for Math 15 ActivityPoints% Final Grade Assignments10020% In-Class Quizzes10020% Computer Labs6012% Project #17014% Project #27014% Final Exam10020% Total500100% ActivityPoints Assignments120 In-Class Quizzes120 Computer Labs60 Project #170 Project #270 Final project100 Total540 Projected points GradeTotal points achieved AOver 425 BOver 375 COver 325 DOver 275

16 UC Merced16 Any Questions?

17 UC Merced17 What is a computer programming?  A computer programming is a sequence of instructions that specifies how to perform a computation. Basically, all computers need someone to tell them what to do!

18 UC Merced18 Next Week  More Programming while statement  General loop for loop statement  A sequence iteration List  Mutable (changeable) arrays of object reference:  i.e. [0,1,2,3] [ ‘ Lions ’, ” Tigers ’, ’ Bears ’, ’ Oh my ’ ]

19 UC Merced19 Quick Reminder – Part 1  List: A list is an ordered set of values, where each value is identified by an index. The values that make up a list are called its elements. UC = [“UCLA”, “UC Davis”, “UC Merced”, “UC Berkeley”, “UCSF”, “UCI”] # of elements in UC = 6 >>> print UC[1] UC Davis >>> print UC[6] Error! Python – Index of List starts at 0

20 UC Merced20 Quick Reminder – Part 2  range() function range(n) : a list of integers from 0 to up to n, but not including n. >>> range(10) [0,1,2,3,4,5,6,7,8,9]

21 UC Merced21 Review: for loop statement  Examples N = 10 for var in range(1,N,2): print var >>> 1 3 5 7 9 Starting Value End Value Increment loopvar 11 23 35 47 59 range(1,N,2)=>range(1,10,2)=[1,3,5,7,9]

22 UC Merced22 Quick Reminder – Part 3 N = 15 icount = 0 # Initializing a variable for var in range(1,N,2): icount = icount + 1 print var, icount >>> 1 3 2 5 3 7 4 9 5 11 6 13 7 Concept of “ Counter ” loopvaricount 111 232 353 474 595 6116 7137 range(1,N,2)=>range(1,15,2)=[1,3,5,7,9,11,13] Counter

23 UC Merced23 Review: while statement  Example N = 10# Set the initial # value of N while N > 0: print N N = N-1 print "Blastoff!" >>> 10 9 8 7 6 5 4 3 2 1 Blastoff! This program reads: "While N is greater than 0, continue displaying the value of N and then reducing the value of N by 1. When you get to 0, display the word Blastoff!"

24 UC Merced24  Any Questions?

25 UC Merced25 Review 1: # # Evaluation of summation print = raw_input("Pick your number. ") for i in range(print): jj = jj + i print i, jj # # Evaluation of summation N = input("Pick your number. ") jj = 0 for i in range(2,N+1): jj = jj + i print i, jj Print is Python ’ s reserved word. It cannot be used as a variable name.

26 UC Merced26 Review 2: # # Evaluation of multiplication N = input("Pick your number. ") jj = 0 for i in range(1,N+1): jj = jj * i print i, jj >>> Pick your number. 8 1 0 2 0 3 0 4 0 5 0 6 0 7 0 8 0 >>>

27 UC Merced27 Review 2 – cont. # # Evaluation of multiplication N = input("Pick your number. ") jj = 1 for i in range(1,N+1): jj = jj * i print i, jj >>> Pick your number. 8 1 2 3 6 4 24 5 120 6 720 7 5040 8 40320 >>>

28 UC Merced28 Some Hints for HW #6  What are “ even ” and “ odd ” numbers? Any integer is either even or odd according to the following rules:  If it is a multiple of two, it is an even number; otherwise, it is an odd number. Evens = {..., −6, −4, −2, 0, 2, 4, 6,...}. Odds = {..., −5, −3, −1, 1, 3, 5,...}.

29 UC Merced29 How to program this?  How to create a program that tells whether user ’ s input number is odd or even. Let ’ s think this statement: “ If it is a multiple of two, it is an even number. ” In another word: “ If it is evenly divided by two, it is an even number. ” “ Evenly divided ” means “ no remainder ”. If there is a python function that can tell us what is a remainder of the division of two integers, we can use it.

30 UC Merced30 Arithmetic Operation table from two weeks ago! Arithmetic Operation FunctionExampleEvaluates To A + BA plus B3 + 47 A – BA minus B4.0 – 5.1-1.1 A * BA times B3 * 515 A / BA divided by B7.0/3.02.333333 A % B A modulo B (Remainder of A divided by B) 7 % 31 A ** BA raised to the power of B2**38

31 UC Merced31 Let’s program this!  How to create a program that tells whether user ’ s input number is odd or even. # Odd or Even A = input(”Pick your number: “) if A%2 == 0: print "Your number ",A," is Even!" else: print "Your number ",A," is Odd!" >>> Pick your number: 81 Your number 81 is Odd! >>> Pick your number: 80 Your number 80 is Even! >>>

32 UC Merced32 from HW #6 >>> 0 Even 1 Odd 2 Even 3 Odd 4 Even 5 Odd 6 Even 7 Odd 8 Even 9 Odd 10 Even 11 Odd 12 Even 13 Odd 14 Even 15 Odd Outputs for #1 and #2 #3 refer to Lab 6 (Distance formula and Quadratic equation.) #4: Solve the systematic equations first in terms of four input variables. Otherwise, similar to #3.

33 UC Merced33 Just Little bit of Mathematics  Let ’ s consider a growth of an investment  Fixed interest rate = r  i.e. Bank and other financial institutions usually quote the rate on a per year basis. r = 5.0 % = 0.05, r = 3.25% = 0.0325 If this is the case, then after one year the account will have earned where P 0 is a original principle.

34 UC Merced34  Then, how much the investor will have as a total after 1-year?  How about 2 nd -year?  How about 10-year later?

35 UC Merced35  Then, how much the investor will have as a total after (n+1)-year later? where n = 0, 1,2,3, …  In Mathematics, this type of the equation is called “ Difference Equation. ”

36 UC Merced36 How are we going to program this? First: the computer needs to have two initial values, P 0 (original principle) and r (interest rate). >>> Original Principle $ 100 Interest rate (between 0 and 1)? 0.1 110.0 >>>

37 UC Merced37 How to make a recursive? >>> Original Principle $ 100 Interest rate (between 0 and 1)? 0.1 1 $ 110.0 2 $ 121.0 3 $ 133.1 4 $ 146.41 5 $ 161.051 6 $ 177.1561 7 $ 194.87171 8 $ 214.358881 9 $ 235.7947691 10 $ 259.37424601 >>> Use “Loop”!

38 UC Merced38 Another way to do this. >>> Original Principle $ 100 Interest rate (between 0 and 1)? 0.1 1 $ 110.0 2 $ 121.0 3 $ 133.1 4 $ 146.41 5 $ 161.051 6 $ 177.1561 7 $ 194.87171 8 $ 214.358881 9 $ 235.7947691 10 $ 259.37424601 >>>

39 UC Merced39 Many ways to program a code!  There is no unique solution to creating a program. i.e. there is no one route from Merced, CA to Tampa, FL.

40 UC Merced40 Any Questions?

41 UC Merced41  Homework #5 due this Friday. (11:45pm on November 2 nd ) Already available in UCMCROP  Next Week, November 7 th – Quiz #5


Download ppt "Math 15 Introduction to Scientific Data Analysis Lecture 9 Python Programming – #3 University of California, Merced."

Similar presentations


Ads by Google