CMPT 120 Introduction to Computer Science and Programming I Chris Schmidt.

Slides:



Advertisements
Similar presentations
Finding Complex Roots of Quadratics
Advertisements

10-6 Solving Quadratic Equations by Factoring
Introduction to Programming
Basics A quadratic equation is an equation equivalent to an equation of the type ax2 + bx + c = 0, where a is nonzero We can solve a quadratic equation.
2.4 Completing the Square Objective: To complete a square for a quadratic equation and solve by completing the square.
The Quadratic Formula for solving equations in the form
solution If a quadratic equation is in the form ax 2 + c = 0, no bx term, then it is easier to solve the equation by finding the square roots. Solve.
Solving Quadratic Equations Algebraically Lesson 2.2.
Quadratic Equations Sum and Product of the Roots.
Objectives: 1. Solve equations by: A. Factoring B. Square Root of Both Sides C. Completing the Square D. Quadratic Formula 2. Solve equations in quadratic.
Lesson 1-6 Solving Quadratic Equations. Objective:
Complex Number A number consisting of a real and imaginary part. Usually written in the following form (where a and b are real numbers): Example: Solve.
Many quadratic equations can not be solved by factoring. Other techniques are required to solve them. 7.1 – Completing the Square x 2 = 20 5x =
7.1 – Completing the Square
EXAMPLE 4 Choose a solution method Tell what method you would use to solve the quadratic equation. Explain your choice(s). a. 10x 2 – 7 = 0 SOLUTION a.
Solving Quadratic Equations by Completing the Square
8/24/2015 V. J. Motto 1 Chapter 2: Review – Quadratic Function V. J. Motto M110 Modeling with Elementary Functions.
DCT 1123 PROBLEM SOLVING & ALGORITHMS INTRODUCTION TO PROGRAMMING.
Solving Quadratic Equations Section 1.3
3.5 Quadratic Equations OBJ:To solve a quadratic equation by factoring.
6.5 – Solving Equations with Quadratic Techniques.
2.3 Part 1 Factoring 10/29/2012. What is Factoring? It is finding two or more numbers or algebraic expressions, that when multiplied together produce.
Introduction to Pharmaceutical Calculation
OLGT: Solving Quadratic Equations Do Now Solve each equation. Decide whether each equation is an identity, a conditional or a contradiction. 1.5(x+3) +
Solving Quadratic Equations Using Completing the Square and the Quadratic Formula.
Goals: To solve quadratic equations by using the Quadratic Formula.
Module :MA0001NP Foundation Mathematics Lecture Week 9.
4.6 The Quadratic Formula and the Discriminant
CS221 Algorithm Basics. What is an algorithm? An algorithm is a list of instructions that transform input information into a desired output. Each instruction.
5.3 – Solving Quadratic Equations by Factoring. Ex. 1 Solve y = x 2 + 5x + 6 by factoring.
The Quadratic Formula Students will be able to solve quadratic equations by using the quadratic formula.
By Kendal Agbanlog 6.1-Measurement Formulas and Monomials 6.2-Multiplying and Dividing Monomials 6.3-Adding and Subtracting Polynomials 6.4-Multiplying.
Completing the Square SPI Solve quadratic equations and systems, and determine roots of a higher order polynomial.
Introduction to design and analysis algorithm
Ch 10: Polynomials G) Completing the Square Objective: To solve quadratic equations by completing the square.
Flowchart. a diagram of the sequence of movements or actions of people or things involved in a complex system or activity. a graphical representation.
PreCalculus Section 1.6 Solve quadratic equations by: a. Factoring b. Completing the square c. Quadratic formula d. Programmed calculator Any equation.
Lesson 2-3 The Quadratic Equation Objective: To learn the various ways to solve quadratic equations, including factoring, completing the square and the.
Solving Quadratic Equations by Using the Quadratic Formula (9-5) Objective: Solve quadratic equations by using the Quadratic Formula. Use the discriminant.
1 Introduction to design and analysis algorithm. 2.
Math 20-1 Chapter 4 Quadratic Equations
1.7 Completing the Square Objective: To complete a square for a quadratic equation and solve by completing the square.
Lesson 6.5: The Quadratic Formula and the Discriminant, pg. 313 Goals: To solve quadratic equations by using the Quadratic Formula. To use the discriminant.
Chapter 4 Quadratic Equations
2.2 Solving Quadratic Equations Algebraically Quadratic Equation: Equation written in the form ax 2 + bx + c = 0 ( where a ≠ 0). Zero Product Property:
Solve Quadratic Functions by Completing the Square
PreCalculus Section 1. 6 Solve quadratic equations by: a. Factoring b
Introduction to Computer Science and Programming I Chris Schmidt
Aim: What are the properties of a quadratic equation?
Quadratic Equations P.7.
Completing the Square Objective: To complete a square for a quadratic equation and solve by completing the square.
Solving quadratics methods
Math 20-1 Chapter 4 Quadratic Equations
Section 11.2 The Quadratic Formula.
The Quadratic Formula.
13.3 Completing the Square Objective: To complete a square for a quadratic equation and solve by completing the square.
9.3 Solve Quadratics by Completing the Square
2.4 Completing the Square Objective: To complete a square for a quadratic equation and solve by completing the square.
5.4 Completing the Square Objective: To complete a square for a quadratic equation and solve by completing the square.
Quadratic Equations and Functions
Review: Simplify.
Ex. 1 Solve by factoring. 2x2 + 9x + 7 = 0 6x2 – 3x = 0
Warm-Up: September 30 / October 1, 2015 Factor each expression
13.3 Completing the Square Objective: To complete a square for a quadratic equation and solve by completing the square.
Completing the Square Objective: To complete a square for a quadratic equation and solve by completing the square.
Warm-Up 5 minutes Factor the following expressions: 2) x2 - 3x
4.5: Completing the square
Chapter 3 Quadratic Equations
13.3 Completing the Square Objective: To complete a square for a quadratic equation and solve by completing the square.
Completing the Square Objective: To complete a square for a quadratic equation and solve by completing the square.
Presentation transcript:

CMPT 120 Introduction to Computer Science and Programming I Chris Schmidt

Algorithms What is an algorithm? What is an algorithm? An algorithm is a set of instructions on how to accomplish something An algorithm is a set of instructions on how to accomplish something The basic idea can be applied to many typical activities The basic idea can be applied to many typical activities Recipes, assembly instructions, directions on how to get somewhere could all be viewed as types of algorithms Recipes, assembly instructions, directions on how to get somewhere could all be viewed as types of algorithms

Algorithms Recipe Example from Study Guide Recipe Example from Study Guide Combine the room-temperature butter and the sugar. Mix until light and fluffy Add the eggs to the creamed butter and mix to combine In another bowl, combine the liquid ingredients and mix to combine Sift together the flour and other dry ingredients Alternately add the dry and liquid ingredients to the butter-egg mixture. Mix just enough to combine.

Algorithms Aspects of a proper algorithm Aspects of a proper algorithm Solves a problem Solves a problem How to make muffins How to make muffins Unambiguous instructions Unambiguous instructions Step 5 isn’t entirely clear Step 5 isn’t entirely clear Completes in a finite amount of time given proper input Completes in a finite amount of time given proper input This clearly does This clearly does

Algorithms What sort of problems are algorithms created for? What sort of problems are algorithms created for? Sorting and searching Sorting and searching We’ll be looking at some well known algorithms for this later in the semester We’ll be looking at some well known algorithms for this later in the semester Encryption and Decryption Encryption and Decryption Mathematical: factoring, finding prime numbers Mathematical: factoring, finding prime numbers Idea can be applied to any problem you want to write code to solve Idea can be applied to any problem you want to write code to solve

Algorithms Check if a user entered number is prime Check if a user entered number is prime 1. Ask the user for a number to check the primeness of. 2. Start with divisor equal to If the user’s number is divided evenly by the divisor, it is not prime. You are done. 4. If the divisor squared is less than the user’s number, increase it by one and go to step If you’ve reached this step, the user’s number is prime.

Algorithms Aspects of a proper algorithm Aspects of a proper algorithm Solves a problem Solves a problem Tests if a user entered number is prime Tests if a user entered number is prime Unambiguous instructions Unambiguous instructions Completes in a finite amount of time given proper input Completes in a finite amount of time given proper input What if step 4 didn’t compare the divisor with the square root of the user’s number? What if step 4 didn’t compare the divisor with the square root of the user’s number?

Pseudocode So far we’ve used natural language to describe algorithms So far we’ve used natural language to describe algorithms It is helpful to describe algorithms in pseudocode (almost code) It is helpful to describe algorithms in pseudocode (almost code) An algorithm written in pseudocode is then easily coded in any give programming language An algorithm written in pseudocode is then easily coded in any give programming language

Pseudocode Digital Clock Example from Study Guide Digital Clock Example from Study Guide set hour to 0 set minute to 0 set second to 0 repeat forever: set second to second + 1 if second is more than 59, then set second to 0 set minute to minute + 1 if minute is more than 59, then set minute to 0 set hour to hour + 1 if hour is more than 23, then set hour to 0 write “hour :minute:second” wait for 1 second

Pseudocode Pseudocode for prime number example Pseudocode for prime number example set divisor to 2 write “Enter an integer greater than 2” read userNumber repeat while divisor 2 < userNumber if userNumber % divisor is equal to 0 write “The number is not prime, it is divisible by :” write divisor exit program set divisor to divisor +1 write “The number is prime.”

Writing a Program Define the problem Define the problem Create a plan (algorithm) to solve the problem Create a plan (algorithm) to solve the problem Translate your algorithm into code Translate your algorithm into code Test and make adjustments to your code and algorithm as neede Test and make adjustments to your code and algorithm as neede

Creating an Algorithm What to keep in mind when creating your algorithm What to keep in mind when creating your algorithm Read in all needed input Read in all needed input Proper output Proper output What are the normal cases (possibilities) based on the input? What are the normal cases (possibilities) based on the input? Are there any special cases? Are there any special cases?

Algorithm Example Problem: Find the roots (real) of a quadratic equation. Problem: Find the roots (real) of a quadratic equation. Quadratic Equation: ax 2 + bx + c Quadratic Equation: ax 2 + bx + c The roots are where this formula is equal to 0, ax 2 + bx + c = 0 The roots are where this formula is equal to 0, ax 2 + bx + c = 0 Ex. a=1,b=0,c=-1 x 2 – 1 = (x-1) * (x+1) = 0 roots at x=1,x=-1 Ex. a=1,b=0,c=-1 x 2 – 1 = (x-1) * (x+1) = 0 roots at x=1,x=-1

Algorithm: Roots of Quadratic Formula How do we find the roots? How do we find the roots? Quadratic equation Quadratic equation Does this formula always work? Does this formula always work?

Algorithm: Roots of Quadratic Formula Input: the coefficients a,b,c Input: the coefficients a,b,c Output: the roots of ax 2 + bx + c Output: the roots of ax 2 + bx + c What cases do we need to handle? What cases do we need to handle?

Algorithm: Roots of Quadratic Formula What cases do we need to handle? What cases do we need to handle? Normal Normal Two distinct roots Two distinct roots One root One root But what special cases do we need to be careful of? But what special cases do we need to be careful of? No roots 4ac > b 2 No roots 4ac > b 2 a=0 (straight line bx+c=0 root at –c/b) a=0 (straight line bx+c=0 root at –c/b) a=0,b=0 (horizontal line, no roots unless c =0) a=0,b=0 (horizontal line, no roots unless c =0) a=0,b=0,c=0 (infinite roots) a=0,b=0,c=0 (infinite roots)

Algorithm: Roots of Quadratic Formula Pseudocode write “Enter the coefficients of the formula:” read a,b,c if a,b,and c equal 0 write “infinite roots” exit if a and b equal 0 write “no roots” exit if a equals 0 root = -c/b write “One root at x=“, root exit...

Testing Remember once you’ve translated your pseudocode into actual code that you need to test every possible case Remember once you’ve translated your pseudocode into actual code that you need to test every possible case